Database Query Problem please help |
[eluser]gork7478[/eluser]
I have this problem and I'm trying to figure out what I'm doing wrong. I like to write out my queries, my own personal preference of course. If I do this: Code: $this->db->where('key', $key); But if I do this Code: $sql = 'SELECT * FROM temp_users WHERE key=? LIMIT 1';
[eluser]jairoh_[/eluser]
try this one Code: $query = $this->db->query($sql, array($key));
[eluser]gork7478[/eluser]
I actually tried that first. And then I tried it that way. Both ways gave the same result.
[eluser]rana[/eluser]
hi gork7478, You are using a mysql reserved word "key" (http://dev.mysql.com/doc/refman/5.0/en/r...words.html) as column name, an that's why you are having issue. Its recommended to use different column name for your database stability. But you should get it working by using the following query string: Code: $sql = 'SELECT * FROM temp_users WHERE [key]=? LIMIT 1'; Hope this helps. Thanks.
[eluser]gork7478[/eluser]
Hi Rana, Thanks for putting me in the right direction. It didn't work with the square brackets, but I did make it work using backticks. Thanks for the help and for the reference link.
[eluser]rana[/eluser]
Oh, yes, sorry for my mistake, I should have asked you what database you are using, what I showed works for 'sql server' database. Great to hear did able to figure it out yourself. Thanks. |
Welcome Guest, Not a member yet? Register Sign In |