动态查询创建 MySQL


Dynamic query creation MySQL

我正在使用mysqli库处理一个项目,我已经到了需要在方法中创建SELECT查询的地步,具体取决于发送的参数。

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

我知道如果参数发送到列和值的位置,我可以创建查询字符串,方法是遍历它们,然后手动将字符串连接到最终查询字符串,但我想知道是否有任何核心库可以让您执行此操作或任何其他方式

你应该使用 PDO 准备语句

     //$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
}