Php CodeIgniter-绑定存在子查询

Php CodeIgniter-绑定存在子查询,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,首先,我对这个框架还不熟悉。检查我试图使用CI数据库对象记录的查询 $where = "(".$this->tbl.".invoiceNumber = '".substr($searchFor,3)."' OR EXISTS (SELECT 1 FROM op_orders_products WHERE idProduct = ".(is_numeric(substr($searchFor,3)) ? substr($searchFor,3) : '-1')."

首先,我对这个框架还不熟悉。检查我试图使用CI数据库对象记录的查询

$where = "(".$this->tbl.".invoiceNumber = '".substr($searchFor,3)."' 
          OR EXISTS (SELECT 1 FROM op_orders_products WHERE idProduct = ".(is_numeric(substr($searchFor,3)) ? substr($searchFor,3) : '-1')." 
          AND idOrder = ".$this->tbl.".id)
       )";
我应该做一个单独的子查询吗?我想把这一切都融合在一起

我就是这样开始的。我想确保变量是绑定的,而不是像原始查询中那样作为字符串传递

$this->db->group_start()
           ->where($this->tbl.".invoiceNumber", substr($searchFor, 3))
           ->or_group_start()
             // I'm missing this EXISTS select subquery
           ->group_end()
         ->group_end()

非常感谢您的帮助。

据我所知,Codeigniter的查询生成器类中不存在等价物。所以我就这样写:

$this->db->group_start()
             ->where($where)
         ->group_end()
$sql = "SELECT * FROM table WHERE a= ? AND b= ?";
$query = $this->db->query($sql, array($a,$b));
见文件

$this->db->escape()
使用CodeIgniter,您可以将变量绑定到查询,如下所示:

$this->db->group_start()
             ->where($where)
         ->group_end()
$sql = "SELECT * FROM table WHERE a= ? AND b= ?";
$query = $this->db->query($sql, array($a,$b));
这将变量$a和$b绑定到查询字符串中相应的位置(?)

$this->db->escape()

此函数用于转义字符串数据并在其周围添加单引号

据我所知,Codeigniter的查询生成器类中不存在等价物。所以我就这样写:

$this->db->group_start()
             ->where($where)
         ->group_end()
$sql = "SELECT * FROM table WHERE a= ? AND b= ?";
$query = $this->db->query($sql, array($a,$b));
见文件

$this->db->escape()
使用CodeIgniter,您可以将变量绑定到查询,如下所示:

$this->db->group_start()
             ->where($where)
         ->group_end()
$sql = "SELECT * FROM table WHERE a= ? AND b= ?";
$query = $this->db->query($sql, array($a,$b));
这将变量$a和$b绑定到查询字符串中相应的位置(?)

$this->db->escape()

此函数用于转义字符串数据并在其周围添加单引号

嗨,Vickel,出于安全原因,我想在$where子句中绑定变量。嗨,Vickel,出于安全原因,我想在$where子句中绑定变量。