Solved

MySQL / PHPMyAdmin question

Posted on 2013-12-09
2
853 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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