Home  >  Article  >  Backend Development  >  $table = '`'.DB_pre.$table.'`';这儿为什么要用到反引号啊?

$table = '`'.DB_pre.$table.'`';这儿为什么要用到反引号啊?

WBOY
WBOYOriginal
2016-06-23 13:44:351150browse

$table = '`'.DB_pre.$table.'`';这儿为什么要用到反引号啊?


回复讨论(解决方案)

因为你加了一个``符号,为了让变量看起来像字符串才加的。

那是数据表名吧

$table = '`'.DB_pre.$table.'`'
反撇号是 mysql 的名称转义符
当你使用 mysql 的保留字作为字段名或表名时,为了防止歧义,要用一对反撇号将其括起
不是保留字就不用转义了
不过当使用程序产生 mysql 指令时,程序并不可能预知动态构建的名字是否是保留字(检查起来也怪麻烦的)所以写程序时都给字段名和表名加上转义

防止??字??的。

例如你的表名是index
 select * form index ?出?。因?index是sql??字。

所以需要?成
select * from  `index `

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn