codenoob codenoob - 2 months ago 9
MySQL Question

mysql where clause resitriction?

I use below php code to generate a random id number

md5(uniqid(rand(), true)


the type of string it generate is something like this

9a423553ce53c4d7a6199fa9254bfdc5


I use that as an ID in Mysql table then I do a standard select query

SELECT * FROM table WHERE id = 9a423553ce53c4d7a6199fa9254bfdc5


I get this error

Unknown column '9a423553ce53c4d7a6199fa9254bfdc5' in 'where clause'


if I just change the id to a simple number like
1
it works.

Why is this?

Answer

Have you tried encapsulating that in quotes? In your query id = 9a423553ce53c4d7a6199fa9254bfdc5 You can compare two columns like id = other_id .. MySQL needs to know how to handle your query.

For clarification, should be: SELECT * FROM table WHERE id = '9a423553ce53c4d7a6199fa9254bfdc5';

Comments