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

我的问题:

  1. 大括号是什么意思?
  2. '%s'%d%f 是什么意思?
  3. 为什么不直接这样写:

    INSERT INTO data (code, nominal, desc, proofnumber, uid) 
        VALUES ($code, $nominal, $desc, $proofnumber, $uid)`?
    
  1. 大括号用于 table 名称的适当前缀,因此 {data} 将变成类似于 myapp_datasee db_prefix_tables for more.
  2. %s,%dsprintf format specifiers, you can find some examples in db_query docs.
  3. 所有这些都是以与数据库无关的方式实现查询(#1)和减轻 SQL 注入(#2)所必需的。