简体   繁体   English

Codeigniter活动记录,用于简单查询

[英]Codeigniter active record for simple query

Please see the following query. 请参阅以下查询。

I want to convert it into codeIgniter active records. 我想将其转换为codeIgniter活动记录。

SQL QUERY: 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");

How can I convert this without using $this->db->query()? 如何不使用$ this-> db-> query()进行转换?

The ActiveRecord style of querying with CodeIgniter escapes parameters, but not db->query() and also db->query() is not SQL Injection protected by default. 默认情况下,使用CodeIgniter进行查询的ActiveRecord样式会转义参数,但db->query()db->query()均不受SQL注入保护。

That's why I want to convert it using codeigniter active records. 这就是为什么我要使用codeigniter活动记录进行转换。

Thanks in advance. 提前致谢。

Found solution regarding my problem 找到有关我的问题的解决方案

Query using ACTIVE RECORD 使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM