i’m seeing strange behavior when doing a SELECT on a table with a simple WHERE clause returns a record that does not match exactly.
my table has a column id int(11) as the primary key. to find a record with the id 5350, for example, the following 2 queries both return the record with the id 5350.
SELECT * FROM mytable WHERE id="5350"
SELECT * FROM mytable WHERE id="5350abcd"
one thought I had was to remove the “” around 5350 but i get the same result. in codeigniter, i tried this:
$where = "id=$my_id";
$this->db->where($where);
why is this happening, and how do i fix it so the non-exact id does not find the record?
In the second query the ID value is not an integer. You need to insure that the value is an integer before running the query, other wise it will cast the value to such.