[英]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.