Bergstr
asked on
MySQL / PHPMyAdmin question
I'm currently using PHP & MySQL together (most of my time these days is spent with MSSQL as opposed to MySQL which may explain this..)
anyway - I've come across a very odd problem - my regular single quotes don't work!
This is initially how my sql query looked:
SELECT * FROM Products WHERE Group=2
which gave the following error:
error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in (path)
So - I went into PHPMyAdmin and run that same SQL from there - it gave me another error saying the syntax was incorrect.
I used the built in PHPMyAdmin search facility and that generated the following query:
SELECT *
FROM `Products`
WHERE `Group` =2
That works fine - it also works in PHP without any errors. If I take the single quotes from Group, it fails.
From what I can tell - this single quote (`) works
but this single quote ( ') doesn't.
and "Group" must have those single quotes around it.
I've done the same test in MSSQL and the following query works fine:
SELECT * FROM TABLE WHERE COLUMN = 2
and it works fine
I've also been running the following with PHP and MYSQL and it works fine:
SELECT * FROM Products
so - is it the fact that my column is called "Groups" - or is this a generic MySQL thing?!
I'm very confused even though I have a work around.
I don't even have this special single quote on my keyboard which is the first challenge!!
Any ideas for a work-around?
Thanks
anyway - I've come across a very odd problem - my regular single quotes don't work!
This is initially how my sql query looked:
SELECT * FROM Products WHERE Group=2
which gave the following error:
error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in (path)
So - I went into PHPMyAdmin and run that same SQL from there - it gave me another error saying the syntax was incorrect.
I used the built in PHPMyAdmin search facility and that generated the following query:
SELECT *
FROM `Products`
WHERE `Group` =2
That works fine - it also works in PHP without any errors. If I take the single quotes from Group, it fails.
From what I can tell - this single quote (`) works
but this single quote ( ') doesn't.
and "Group" must have those single quotes around it.
I've done the same test in MSSQL and the following query works fine:
SELECT * FROM TABLE WHERE COLUMN = 2
and it works fine
I've also been running the following with PHP and MYSQL and it works fine:
SELECT * FROM Products
so - is it the fact that my column is called "Groups" - or is this a generic MySQL thing?!
I'm very confused even though I have a work around.
I don't even have this special single quote on my keyboard which is the first challenge!!
Any ideas for a work-around?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much for the answer and the explanation!