flyhoney Posted April 13, 2007 Share Posted April 13, 2007 It appears that mysql queries work without the `` most of the time, but sometimes it complains, why? works most of the time: $query = "SELECT * FROM table WHERE this='$that'"; but sometimes complains and needs: $query = "SELECT * FROM `table` WHERE this='$that'"; why? Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted April 13, 2007 Share Posted April 13, 2007 MySQL might be complaining if you had a table named table since table is a reserved word in MySQL, so quoting is required so MySQL is not trapped in a land of indecision. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted April 13, 2007 Author Share Posted April 13, 2007 No that is not the name of my table, I was just using that as an example. Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted April 13, 2007 Share Posted April 13, 2007 well, whatever the table name is is probably a word already used by MySQL. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted April 13, 2007 Author Share Posted April 13, 2007 So maybe my table name is a reserved word? That makes sense. Sorry, I took the time and did a little more googling and it seems there are several reasons backticks are necessary, I guess I'll just get in the habit of using them. Never seemed to be a problem on DB2 or Oracle. Thanks. Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted April 13, 2007 Share Posted April 13, 2007 I have never found quoting necessary but there usage is probably good coding practice. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 13, 2007 Share Posted April 13, 2007 So maybe my table name is a reserved word? That makes sense. Sorry, I took the time and did a little more googling and it seems there are several reasons backticks are necessary, I guess I'll just get in the habit of using them. Never seemed to be a problem on DB2 or Oracle. Thanks. I have never found quoting necessary but there usage is probably good coding practice. I disagree -- if you get into the habit of NOT using them, you'll learn the reserved keywords and never have a problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.