0
votes

Please see the following query.

I want to convert it into codeIgniter active records.

SQL QUERY:

$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()?

The ActiveRecord style of querying with CodeIgniter escapes parameters, but not db->query() and also db->query() is not SQL Injection protected by default.

That's why I want to convert it using codeigniter active records.

Thanks in advance.

1
You are asking a question off my one I think you have added this as a question instead of answer stackoverflow.com/questions/40055401/…Mr. ED
u already know that query is properly workingdhruv jadia
No it is not sorryMr. ED
@wolfgang1983 using active record query and simple query both are workingdhruv jadia

1 Answers

0
votes

Found solution regarding my problem

Query using 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();