Jump to content

The significance of back-ticks in php mysql queries.


joe92

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.