Solved

MySQL / PHPMyAdmin question

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now