Solved

MySQL / PHPMyAdmin question

Posted on 2013-12-09
2
833 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 42

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test if unique ID is in log file 5 22
PHP Mail error 3 28
Shrink multiple databases at once 4 29
MySQL Finding Duplicates in a Normalized Database 6 12
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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 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