[英]Codeigniter active record for simple query
请参阅以下查询。
我想将其转换为codeIgniter活动记录。
SQL查询:
$this->db->query("SELECT SUM(A.votes) as reputation from
(
SELECT reply.votes FROM reply where reply.user_id = $user_id
UNION ALL
SELECT thread.votes FROM thread where thread.user_id = $user_id
)AS A");
如何不使用$ this-> db-> query()进行转换?
默认情况下,使用CodeIgniter进行查询的ActiveRecord样式会转义参数,但db->query()
和db->query()
均不受SQL注入保护。
这就是为什么我要使用codeigniter活动记录进行转换。
提前致谢。
找到有关我的问题的解决方案
使用ACTIVE RECORD查询
$this->db->select("SUM(A.votes) as reputation");
$this->db->from("(
SELECT reply.votes FROM reply where reply.user_id = $user_id
UNION ALL
SELECT thread.votes FROM thread where thread.user_id = $user_id) AS A");
$query = $this->db->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.