joe92 Posted May 24, 2011 Share Posted May 24, 2011 SELECT * FROM `posts` WHERE `ID` = '$users_ID' LIMIT 0 , 30 or SELECT * FROM posts WHERE ID = '$users_ID' LIMIT 0 , 30 I have been using the second example of above, I don't bother with the back-ticks. However, I was wondering, do they actually speed up the queries? Joe Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/ Share on other sites More sharing options...
trq Posted May 24, 2011 Share Posted May 24, 2011 They have nothing to do with speed but simply allow you to escape reserved words. They should be avoided IMO. Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/#findComment-1219501 Share on other sites More sharing options...
DaiLaughing Posted May 24, 2011 Share Posted May 24, 2011 I don't know if there is a speed implication but there is a security one. Supposedly backticks protect against SQL injection where field names are put in by the user (which is rare for - a CMS or PHPMyAdmin need them but I don't go that far with my sites). I must admit I leave them out and hope I will remember to add them if ever the user inputs field names with POST or GET. I did once find myself accidentally using a reserved word as a field name which meant I had to use them as thorpe says but I then changed the field name which seemed a better solution. Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/#findComment-1219503 Share on other sites More sharing options...
trq Posted May 24, 2011 Share Posted May 24, 2011 Backticks off absolutely no protection against SQL injection. Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/#findComment-1219506 Share on other sites More sharing options...
DaiLaughing Posted May 24, 2011 Share Posted May 24, 2011 Ticks do help against primitive SQL injection but are easy to get around. That's why I said "supposedly". I should have been clearer that they are not a valid security measure though! Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/#findComment-1219516 Share on other sites More sharing options...
The Little Guy Posted May 25, 2011 Share Posted May 25, 2011 They should be avoided IMO. I second that, you should avoid naming column as a reserved word. If you do name it as a reserved word, you probably didn't name the column very well Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/#findComment-1220074 Share on other sites More sharing options...
fenway Posted May 27, 2011 Share Posted May 27, 2011 Reserved keywords come and go -- if you're dealing with an older system, you may have no choice but to use backticks. Quote Link to comment https://forums.phpfreaks.com/topic/237320-the-significance-of-back-ticks-in-php-mysql-queries/#findComment-1221098 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.