<分区>
下面两个查询有什么区别?
mysql_query("UPDATE table SET name = '$name'");
mysql_query("UPDATE table SET name = '{$name}'");
<分区>
下面两个查询有什么区别?
mysql_query("UPDATE table SET name = '$name'");
mysql_query("UPDATE table SET name = '{$name}'");
最佳答案
在 SQL 方面,绝对没有区别:两个查询完全相同。
(您可以通过回显它们来检查)
{$variable}
是 $variable
的一种更完整的语法,它允许使用:
"这是一些 {$variable}s"
"{$object->data}"
"{$array['data']}"
"{$array['data']->obj->plop['test']}"
如需更多信息,请阅读 Variable parsing / Complex (curly) syntax手册的部分(引用一些位):
This isn't called complex because the syntax is complex, but because it allows for the use of complex expressions.
Any scalar variable, array element or object property with a string representation can be included via this syntax.
Simply write the expression the same way as it would appear outside the string, and then wrap it in{
and}
.
关于php - {} 如何影响 PHP 中的 MySQL 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5370426/