Welcome Guest, Not a member yet? Register   Sign In
Problem with where clause in active record class (solved)
#1

[eluser]Unknown[/eluser]
$params['title'] is a string and $params['feed'] is an integer. Column's 'title' type is varchar and column's 'feed' type is integer. The PHP code is:

Code:
$this->db->where('title', $params['title']);
$this->db->where('feed', $params['feed']);
$query = $this->db->get('news');

So everything should be fine, BUT...
Quote:A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'riots: intense anger after deaths of three young men AND `feed` = '1'' at line 3
SELECT * FROM (`news`) WHERE `title` = Birmingham riots: intense anger after deaths of three young men AND `feed` = '1'
Filename: C:\path\system\database\DB_driver.php
Line Number: 330

Of course, it's obvious why an error occurred.
Solved by changing to
Code:
$this->db->where('title', (string) $params['title']);
And other clause accordingly. And now have a bunch of identical errors in other models.
Why CI didn't automatically determine the syntax of the SQL query?
Using CI 2.0.2 and MySQL 5.5.10

EDIT
$params['title'] is a property of object created by SimpleXML and that property's type is object, not string. Fixed.




Theme © iAndrew 2016 - Forum software by © MyBB