Codeigniter如何删除子查询中的"`"

Chu*_* Le 2 php mysql codeigniter

我在from子句中运行子查询时遇到问题.
这是我的代码

$subquery = "select column1, column2 from table limit 10, 10"
$this->db->select(column1, false)->from("( $subquery ) as b");
$this->db->get();
Run Code Online (Sandbox Code Playgroud)

我得到数据库错误"Undeclared variable:10"并打印我的查询是:

select column1 from ((select column1, column2 from table limit 10, `10` ) as b)
Run Code Online (Sandbox Code Playgroud)

如何删除此字符"`"

Cod*_*fee 5

你可以使用$ this-> db - > _ protect_identifiers = false; 这将删除此查询的所有反引号.

所以你的查询将是这样的:

$subquery = "select column1, column2 from table limit 10, 10"
$this->db->_protect_identifiers=false;
$this->db->select(column1, false)->from("( $subquery ) as b");
$this->db->_protect_identifiers=true;   // You can make it true again here to avoid removing of backtickes in further code unnecessarily 
$this->db->get();
Run Code Online (Sandbox Code Playgroud)