Drupal 7 db_query

Joh*_*lan 3 database drupal-7

我正在寻找的完美小模块是为drupal 6做的,但令我沮丧的是它不适用于drupal 7.我已经知道drupal 7有一个新的数据库api.我试图让它发挥作用,但我无可否认地离开了我的联盟.我希望有人可以给我一些指导.特别是db_query.

function webform_image_validation_webform_validation_validate($validator_name, $items,   
$components, $rule) {
$errors = array();
if ($items) {
switch ($validator_name) {
  case 'max_image_size':
    $dimensions = explode('x', $rule['data']);
    foreach ($items as $key => $val) {
      if (is_numeric($val['_fid'])) {
        $result = db_query("select * from {files} where fid = %d", $val['_fid']);
        while ($data = db_fetch_object($result)) {
          $thefile = $data;
        }
        $image_info = image_get_info($thefile->filepath);
        if (webform_image_validation_validate_image($image_info, $dimensions[0], $dimensions[1], FALSE) === FALSE) {
          $errors[$key] = t('Your image did not match the required width and/or height. (') . $dimensions[0] . t(' x ') . $dimensions[1] . t(')');
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误.

Argument 2 passed to db_query() must be an array, string given, called in
/home/designco/public_html/dev/sites/all/modules/webform_image_validation/
webform_image_validation.module on line 69 and defined in
/home/designco/public_html/dev/includes/database/database.inc on line 2310
Run Code Online (Sandbox Code Playgroud)

看来我需要添加一个数组,但我迷失了.任何帮助,将不胜感激.我只是想弄清楚我是不是正确的赛道.

小智 15

db_query在Drupal7中的工作方式不同.


$result = db_query("select * from {files} where fid = %d", $val['_fid']);
while ($data = db_fetch_object($result)) {
  $thefile = $data;
}
becomes

$results = db_query("select * from {files} where fid = :fid", array(':fid' => $val['_fid']));
foreach($results as $result) {
  // Do your thing for each result.
}