我在from子句中运行子查询时遇到问题。
这是我的代码
$subquery = "select column1, column2 from table limit 10, 10"
$this->db->select(column1, false)->from("( $subquery ) as b");
$this->db->get();
我收到数据库错误“未声明的变量:10” 打印我的查询是:
select column1 from ((select column1, column2 from table limit 10, `10` ) as b)
如何删除此字符“`”
答案 0 :(得分: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();
答案 1 :(得分:0)
试试这个:
$subquery = "select column1, column2 from table limit 10, 10";
$this->db->query("Select column1 from (".$subquery.") as b" );