Drupal 查询中大括号和 %s 以及 %f 和 %d 的含义是什么?
What are the meaning of curly brackets and %s and %f and %d in Drupal queries?
我必须检查来自 Web 应用程序的脚本(基于 PHP,内置于 Drupal 6,但我认为这只是一个不特定于 drupal 6 的通用脚本,cmiiw)。但我仍在学习它。
代码如下:
db_query("INSERT INTO {data} ( code, nominal, desc, proofnumber, uid)
VALUES ('%s', %f,'%s', '%s', %d)", $code, $nominal, $desc, $proofnumber, $uid);
我的问题:
- 大括号是什么意思?
'%s'
、%d
和 %f
是什么意思?
为什么不直接这样写:
INSERT INTO data (code, nominal, desc, proofnumber, uid)
VALUES ($code, $nominal, $desc, $proofnumber, $uid)`?
- 大括号用于 table 名称的适当前缀,因此
{data}
将变成类似于 myapp_data
、see db_prefix_tables for more.
%s
,%d
等sprintf format specifiers, you can find some examples in db_query docs.
- 所有这些都是以与数据库无关的方式实现查询(#1)和减轻 SQL 注入(#2)所必需的。
我必须检查来自 Web 应用程序的脚本(基于 PHP,内置于 Drupal 6,但我认为这只是一个不特定于 drupal 6 的通用脚本,cmiiw)。但我仍在学习它。
代码如下:
db_query("INSERT INTO {data} ( code, nominal, desc, proofnumber, uid)
VALUES ('%s', %f,'%s', '%s', %d)", $code, $nominal, $desc, $proofnumber, $uid);
我的问题:
- 大括号是什么意思?
'%s'
、%d
和%f
是什么意思?为什么不直接这样写:
INSERT INTO data (code, nominal, desc, proofnumber, uid) VALUES ($code, $nominal, $desc, $proofnumber, $uid)`?
- 大括号用于 table 名称的适当前缀,因此
{data}
将变成类似于myapp_data
、see db_prefix_tables for more. %s
,%d
等sprintf format specifiers, you can find some examples in db_query docs.- 所有这些都是以与数据库无关的方式实现查询(#1)和减轻 SQL 注入(#2)所必需的。