我使用codeigniter,为了安全起见,我尝试使用查询绑定来逃避查询,但是在使用limit语法时遇到了问题。
在我进一步解释之前,请看一下下面的问题;
我的问题
$query = "
SELECT * FROM messages
WHERE id = ?
AND public = ?
ORDER BY `messages`.`time` DESC LIMIT ?, ?
";
// Step one, escaping all queries
$bind = array($id, $public, $start, $max);
$query = $this->db->query($query, $bind);
// Step two, using the query above, and inserting it as a string into a "custom query handeler function"
return $this->db->escape_str($this->handel_all_queries($query));
问题一:
所以,使用 DESC LIMIT ?, ?
给我一个错误。当它没有使用查询绑定转义时(例如,如果我们将限制语法表示为 DESC LIMIT $start, $max
. 但很明显,这样做是不安全的,我正试图逃避它,就像查询的其余部分一样。
问题二:
然后我想在另一个处理所有查询调用的函数中使用“query as a string”。函数被调用 handel_all_queries
.
我曾经尝试实现的代码是-> return $this->db->escape_str($this->handel_all_queries($query));
. 我认为,$query可以用作字符串来传输到下一个函数,但它不是。
请注意,简单地说,这是我想做的,但这些是非常不受保护的。
$query = "
SELECT * FROM messages
WHERE id = $id
AND public = $public
ORDER BY `messages`.`time` DESC LIMIT $start, $max
";
return $this->db->escape_str($this->handel_all_queries($query));
提前谢谢
暂无答案!
目前还没有任何答案,快来回答吧!