开发者

PDOStatement - Use grave accents (`) in columns?

Looking at the PHP manual, does not, at any time, the suggestion to include the grave accents on the columns.

For example: recently, I was trying to run the function below:

 $pdo->prepare("UPDATE name_table SET convert= :convert, payment = :payment WHERE 开发者_运维百科id = :id") 

After repeated attempts to try to update the data in MySQL, I noticed that the CONVERT function is a function of the native MySQL.

So after that, put the backticks in the columns and it worked:

 $pdo->prepare("UPDATE name_table SET `convert`= :convert, `payment` = :payment WHERE id = :id") 

Does anyone believe that the grave accents are not essential to the object PDOStatements? Just tried to MySQL, but do not know if it really is good to use backticks to further change the database.


I would imagine backticks are not required or mentioned because they are specific to mysql and PDO was designed to be used with any RDMS.


As you say yourself, your query didn't work because CONVERT is a reserved word in mySQL, and whenever using column names that are reserved words - or have other weird characteristics - you need to wrap them in backticks.

There's no harm in using backticks for every column and table name. Just don't use them on data - that doesn't work. For data, use quotes instead.

Edit after @Beau's answer: Note that this applies only to mySQL!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜