I'm trying to do a simple select on a table with a simple where clause. Basically:
$query = "Select * from devices where device_id = 'abcdefghijklmnopqrstuvwxyz000000'";
When I try to execute the query, I get the error
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 '' at line 128
If I shorten $id
by 1 character, it works, or if I try to query a different field, it's fine. Obviously this is something to do with the datatype being stored in the table. The field device_id is char(32)
, so I understand if the query wouldn't take values greater in length than that, but $id
has a length of 32.
Even copying the value from the device_id
column in phpMyAdmin and pasting it as the value for $id
in my php doesn't work. Something seems fishy... What's going on, and how can I fix it?
I've gotten some comments about changing the datatype, and stating that 'abcdefghijklmnopqrstuvwxyz000000' is too large to store in the table. However, it isn't.
Let me clarify my question:
The value stored in this column in the db is 'abcdefghijklmnopqrstuvwxyz000000'. The value in my query is the exact same value: 'abcdefghijklmnopqrstuvwxyz000000';
Both have a strlen of 32, and the datatype of that column is char(32).
Why will the table store the value 'abcdefghijklmnopqrstuvwxyz000000', but not let me query against that value? This doesn't seem correct.