楼上的意思是我传到php界面根据参数 组合出不同的语句 like <?php $par = $_POST['par']; switch($par[0]) { case "s" select name from xx where xx ...组合成select查询 case 'i' insert into tb_name values(xx,xx) ..组合 insert语句 case 'd' delete from name where xx 组合 delete语句 } ?>这样传递的参数太多。表名也需要传递。还要传递列名等等。很麻烦
楼上的意思是我传到php界面根据参数
组合出不同的语句 like <?php
$par = $_POST['par'];
switch($par[0])
{
case "s" select name from xx where xx ...组合成select查询
case 'i' insert into tb_name values(xx,xx) ..组合 insert语句
case 'd' delete from name where xx 组合 delete语句
}
?>这样传递的参数太多。表名也需要传递。还要传递列名等等。很麻烦
我的 ajaxcommon.php实际上是这样设计的class AjaxCom extends conn
{
protected $_sql = null;
protected $_conn = null;
//构造函数
public function __construct()
{
//没有接受到参数
if(count($_POST["sql"]) == 0 || !$_POST['sql'])
{
echo 'error';
exit;
}
else
$this->_sql = explode("[~]",iconv("UTF-8","gb2312",trim($_POST["sql"])));
$this->_conn = new conn();
}
//执行语句
public function execute()
{
$msg = '';
$this->_conn->autocommit(false);
foreach($this->_sql as $value)
{
//查询 一般只有一条语句
if(strtolower(substr(trim($value),0,6)) == 'select')
{
$rs = $this->_conn->fetch_one($value);
}
else
{
$this->_conn->query($value);
$rs = $this->_conn->rows();
}
if(!isset($rs))
{
$msg = 'error';
break;
}
}
$msg = $rs;
if(strtolower($msg) == 'error')
//语句出错回滚事务
$this->_conn->rollback();
else
//如果语句全部执行提交事务
$this->_conn->commit();
echo $msg;
}
}
$ajax = new AjaxCom();
$ajax->execute();