Solved

MySQL / PHPMyAdmin question

Posted on 2013-12-09
2
810 Views
Last Modified: 2013-12-09
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
0
Comment
Question by:Bergstr
2 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 39705988
GROUP is reserved word on MySQL and you should not use column names equal to reserved words unles you enclose such names into back apostrophes (backticks) ` (ASCII value 96) You may press Alt key and 96 on any keyboard to enter this character. The obvious key posotion is on the top left corner of the keyboard just below Esc key.

Another possibility is to copy this character by CTRL-C and paste it to given place by CTRL-V

BTW, MS SQL also offers quoted identifiers which are represented by square brackets.

You mey read more about MySQL quoted identifiers here: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
So double quotes are an option.
0
 

Author Comment

by:Bergstr
ID: 39705999
Thought it might be something to do with the name! Just changed it from Group to ProductGroup and we are back to normality!

Thanks very much for the answer and the explanation!
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now