MySQL Forums
Forum List  »  PHP

Re: how to use PHP variable in MYSQL query?
Posted by: Paul Ferrett
Date: January 30, 2008 08:53PM

Using backquotes in your query is like escaping a string.

If you have used reserved words (such as 'set', 'update' etc), or operators (such as -, + etc) as table/field names, MySQL will evaluate those as such.

I.e. if you were to write the query:

SELECT my-col FROM tbl_a

MySQL would assume you wanted to subtract the field `my` from the field `col`. Hence, `my-col` needs to be enclosed in backquotes.

SELECT mycol FROM tbl_a

would work perfectly fine in all versions of MySQL.

Options: ReplyQuote


Subject
Written By
Posted
Re: how to use PHP variable in MYSQL query?
January 30, 2008 08:53PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.