In some code i see people put ` around their columns. Why? IS there any difference from not using them?
SELECT `players`.`name`, `houses`.`id` FROM `players`, `houses`
WHERE `houses`.`owner` = `players`.`id`
Using the backquotes allows reserved words to be used as column or table names e.g.
SELECT `values` FROM `references` WHERE `precision` > 0
and names with nonalphanumerics must be enclosed between the "`"s too, e.g.
SELECT `user name` FROM `registered users` WHERE `total score` > 0
See http://dev.mysql.com/doc/refman/5.1/en/identifiers.html for detail.
I think this is often seen when those names are used dynamically, e.g. (artificial example)
mysql_prepare_statement("SELECT `%q` FROM `%q` WHERE `%q` > 0", col, tbl, col_cond);
in this form, any kinds of column and table names can be handled identically, and malicious injection attempts such as col = "1; DROP TABLE users--"
can be avoided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With