How can I write SQL for a table that shares the same name as a protected keyword in MySql?


This question already has an answer here:


Order is a reserved word. Don't use reserved words as table or field names; or wrap it in the escape characters such as ` for mysql. Personally I just avoid using them as they generally cause more headache than they are worth in the long run.


mysql_query("SELECT * FROM `order` WHERE orderID = 102;");

MORE INFO - you can get more info about reserved word here

Drives me crazy that people assume queries will work, and then don't even bothering asking the database to explain why things blew up. Try this:

$result = mysql_query("SELECT * FROM order WHERE orderID = 102;") or die(mysql_error());

as well, unless there's more code than what you're showing above, you HAVE to capture the return value of the query call, since that return value is your result handle, from which you fetch results. Without that statement handle, you're basically wasting the DB server's (and your own) time.

Try mysql_query("SELECT * FROM order WHERE orderID = 102;") or die("MySQL ERROR: ".mysql_error());

Need Your Help

Twitter Bootstrap Modal does not appear

javascript jquery html twitter-bootstrap modal-dialog

Any modal that I am creating using twitter bootstrap fails to appear. I'm not sure what I'm doing wrong seeing that I set up a test modal using the code that bootstrap provides and it still doesn't...

how to connect to SQL Server with SQuirreL SQL from non domain registered Linux box?

sql-server linux dns squirrel-sql

I need to connect to a SQL 2008 R2 Server from my Linux box that's not registered in my company's domain. I'm trying to use SQuirreL SQL version 3.2.1.