$query = "SELECT * FROM `users` WHERE `username` = 'admin'";#works
$query = "SELECT * FROM 'users' WHERE 'username' = 'admin'";#does not work
Is this yet another quirk Im going to have to get used to, or is something funny going on?
$query = "SELECT * FROM `users` WHERE `username` = 'admin'";#works
$query = "SELECT * FROM 'users' WHERE 'username' = 'admin'";#does not work
Is this yet another quirk Im going to have to get used to, or is something funny going on?
Single quotes ('
) and double quotes ("
) are used to specify strings in MySQL. Backticks (`
) are used for column/table references.
Your second query will fail for two reasons:
'users'
specifies a string, not a reference to the table users
, and FROM
expects a table reference.'username' = 'admin'
does a string comparison, and the string username
is never equal to the string admin
.It's not legal syntax to quote the name of a column with '
The ` (backtick) is used to quote identifiers.
Since none of your columns are reserved keywords, this would work too:
"SELECT * FROM users WHERE username = 'admin'"
In MySQL, by default single-quotes ('
) and double-quotes ("
) are literal string delimiters, while backticks (`
) are identifier quotes. If you set the SQL mode to include ANSI_QUOTES, then double-quotes will also be identifier quotes rather than literal string delimiters.