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? Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/ 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. Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/#findComment-228195 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. Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/#findComment-228196 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. Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/#findComment-228203 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. Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/#findComment-228206 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. Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/#findComment-228214 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. Link to comment https://forums.phpfreaks.com/topic/46814-query-syntax-or-just-syntax/#findComment-228427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.