PDOStatement - 在列中使用重音符号 (`)?

发布于 2024-10-14 03:06:03 字数 453 浏览 1 评论 0 原文

查看 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疑心病 2024-10-21 03:06:03

我想不需要或提及反引号,因为它们是特定于 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.

软的没边 2024-10-21 03:06:03

正如您自己所说,您的查询不起作用,因为 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文