查看 PHP 手册,在任何时候都没有建议在列上包含重音符号。
例如:最近,我尝试运行以下函数:
$pdo->prepare("UPDATE name_table SET convert= :convert, payment = :payment WHERE id = :id")
在反复尝试更新MySQL中的数据后,我注意到CONVERT函数是本机MySQL的函数。
所以在那之后,在列中添加反引号,它就起作用了:
$pdo->prepare("UPDATE name_table SET `convert`= :convert, `payment` = :payment WHERE id = :id")
有人认为重音符号对于 PDOStatements 对象不是必需的吗?刚刚尝试了MySQL,但不知道使用反引号来进一步更改数据库是否真的很好。
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.
发布评论
评论(2)
我想不需要或提及反引号,因为它们是特定于 mysql 的,并且 PDO 被设计为与任何 RDMS 一起使用。
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.
正如您自己所说,您的查询不起作用,因为
CONVERT
是 保留字,每当使用保留字的列名 - 或具有其他奇怪的特征 - 你需要将它们用反引号括起来。对每个列和表名使用反引号没有什么坏处。只是不要在数据上使用它们 - 这是行不通的。对于数据,请使用引号。
在@Beau的回答后编辑:请注意,这仅适用于 mySQL!
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!