Solved

MySQL / PHPMyAdmin question

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sort in mysql based off of query param 4 24
paypal ipn url 5 57
Decrypt string by php 7 31
Logic behind "best rated" calculation 11 22
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 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