![]() |
Database Query Problem please help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Database Query Problem please help (/showthread.php?tid=57949) |
Database Query Problem please help - El Forum - 04-29-2013 [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'; Database Query Problem please help - El Forum - 04-29-2013 [eluser]jairoh_[/eluser] try this one Code: $query = $this->db->query($sql, array($key)); Database Query Problem please help - El Forum - 04-29-2013 [eluser]gork7478[/eluser] I actually tried that first. And then I tried it that way. Both ways gave the same result. Database Query Problem please help - El Forum - 04-29-2013 [eluser]rana[/eluser] hi gork7478, You are using a mysql reserved word "key" (http://dev.mysql.com/doc/refman/5.0/en/reserved-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. Database Query Problem please help - El Forum - 04-29-2013 [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. Database Query Problem please help - El Forum - 04-29-2013 [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. |