08-21-2009, 10:37 AM
|
#7 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
It doesn't pass byRef just looked through the source, do you understand what I'm getting at?
Take this example:
PHP Code:
$sql = "SELECT username FROM users WHERE password = '?'";
function query($sql, $repl) { $sql = str_replace('?', $repl, $sql); }
function queryref(&$sql, $repl) { $sql = str_replace('?', $repl, $sql); }
query($sql, 'cheese'); echo $sql . '<br />'. '<br />'. '<br />';
queryref($sql, 'cheese'); echo $sql;
Results:
Code:
SELECT username FROM users WHERE password = '?'
SELECT username FROM users WHERE password = 'cheese'
Basically the $sql variable in your example is in a different namespace to $this->db->query's $sql variable (as method/function params are passed byVal by default) therefore when you echo $sql; out it will still equal the value you set.
To replicate the behaviour you want/need, you could do a call-time-pass-by-reference call:
PHP Code:
$sql = "SELECT articles.body, articles.user_id, users.username FROM articles, users WHERE ? = 1 AND articles.user_id = users.user_id ORDER BY ?";
$query = $this->db->query(&$sql, array('item1', 'item2')); echo $sql;
This is apparently deprecated behavior however and may result in a warning.
Having not tested CI i can't be 100% thats why it isnt working, but im pretty sure (after a quick skim read of the code)
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|