动态查询创建MySQL

时间:2013-12-10 14:53:09

标签: php mysql mysqli

我正在使用mysqli库进行项目,我已经达到了需要在方法内创建SELECT查询的程度,具体取决于发送的参数。

我正在寻找的行为类似于Android的SQLite,您可以将列作为参数传递,将值作为下一个参数传递。

我知道我可以创建查询字符串,如果参数发送到列和值的位置,通过迭代它们然后手动将字符串连接到最终查询字符串,但我想知道是否有任何核心库可以让你做这种或任何其他方式

1 个答案:

答案 0 :(得分:0)

您应该使用PDO prepared statements

     //$param = array(":querycon1" => "querycon", ":querycon2" => "querycon2");
     // $condition = "abc=:querycon1 AND xyz=:querycon2";

     protected function setQuery($column,$condition,$param){

       $this->query = "SELECT $column FROM tablename WHERE $condition";

       $this->param = $param // 
    $this->getQuery($this->query, $this->param); // to a method that processes the query
}