Welcome Guest, Not a member yet? Register   Sign In
How to Force Code Igniter to NOT to excape queries?
#1

[eluser]Sheikh Aman Alam[/eluser]
I wish to run this query-

Code:
SELECT `comment`.`commenttext`, `comment`.`cd`, `user`.`username`
FROM (`user`, `comment`)
WHERE `comment`.`videoid` = '2'
AND `comment`.`isactive` = 1
AND `user`.`userid` = comment.userid

so i fired this command-
[code]
$criteria = array(
       'comment.videoid'=>$videoid,
       'comment.isactive'=>1,
       'user.userid'=>'comment.userid'
          );
$selectWhichColumns = 'comment.commenttext,comment.cd,user.username';
$selectFromTable = 'user';
$data['response'] = $this->comment_model->_selectAND($criteria,$selectWhichColumns,$selectFromTable);

the _selectAND() method uses where to run these queries.
but this methods gives my following output-

Code:
SELECT `comment`.`commenttext`, `comment`.`cd`, `user`.`username`
FROM (`user`, `comment`)
WHERE `comment`.`videoid` = '2'
AND `comment`.`isactive` = 1
AND `user`.`userid` = comment.userid


MySQL isn't accepting the comment.id in quotes, so i want to stop codeigniter from escaping i with quotes.

i know how to do it with set() in INSERT statements, but not in this one.
please help.

Thanks in advance.
#2

[eluser]Georgi Veznev[/eluser]
Code:
$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
$query = $this->db->get('mytable');
#3

[eluser]danmontgomery[/eluser]
Do you mean:

Code:
WHERE `comment`.`videoid` = '2'

? Try:

Code:
$criteria = array(
    'comment.videoid'=>(int)$videoid,
    'comment.isactive'=>1,
    'user.userid'=>'comment.userid'
);

The above post will prevent CI from escaping fields, but not values if it thinks the value is a string
#4

[eluser]Michael Wales[/eluser]
Wouldn't it be much easier to just select on the comment table and join the user table?
#5

[eluser]Sheikh Aman Alam[/eluser]
@noctrum-
i didnt want to this:
WHERE `comment`.`videoid` = '2'

rather, i want to do this:
`user`.`userid` = comment.userid

and NOT this one:
`user`.`userid` = 'comment.userid'

codeigniter is doing the later one.


@michael Wales.
how to do that in this situation?
#6

[eluser]Sheikh Aman Alam[/eluser]
Got it working.
used the join() method and now the code is like-

$this->db->select(`comment`.`commenttext`, `comment`.`cd`, `user`.`username`);
$this->db->from('comment');
$this->db->join('user','user.userid=comment.userid');
$this->db->where($criterea);
$resultSet= $this->db->get()

thanks a lot for giving ideas guys..
:-)




Theme © iAndrew 2016 - Forum software by © MyBB