PDOStatement-在列中使用重音符号(`)吗? [英] PDOStatement - Use grave accents (`) in columns?

查看:56
本文介绍了PDOStatement-在列中使用重音符号(`)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何时候,只要查看PHP手册,都不会在列中包含严重的重音符号.

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") 

反复尝试尝试更新MySQL中的数据后,我注意到CONVERT函数是本机MySQL的函数.

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") 


有没有人相信重音对对象PDOStatements不是必不可少的?刚刚尝试使用MySQL,但不知道使用反引号进一步更改数据库是否真的好.


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.

推荐答案

您自己说,由于CONVERT

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.

在@Beau回答后请注意,这仅适用于mySQL!

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

这篇关于PDOStatement-在列中使用重音符号(`)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆