db fetch array drupal 7

时间:2013-09-10 20:19:27

标签: php mysql drupal drupal-7

我遇到从drupal 6到7网站迁移的问题。我是PHP和MySQL的初学者,我无法找到解决问题的方法。

我正在努力的代码如下:

$sql = "select ID_Speler from TB_Spelers where uid = ".$id;
$row = db_fetch_array(db_query($sql));
$speler = $row['ID_Speler'];

我总是得到一个“调用未定义函数db_fetch_array()”

非常感谢任何帮助。

3 个答案:

答案 0 :(得分:2)

在Drupal 7中使用它:

$query = db_select('field_data_field_order_no', 'fdfon');
$query->addField('fdfon', 'entity_id', 'nid');
$query->addField('fdfnt', 'field_notification_type_value', 'type');
$query->join('field_data_field_notification_type', 'fdfnt', 'fdfon.entity_id = fdfnt.entity_id AND (fdfon.bundle = :fdfon_bundle AND fdfnt.bundle = :fdfnt_bundle)', array(':fdfon_bundle' => "order_notification_type", ':fdfnt_bundle' => "order_notification_type"));
$query->condition('fdfon.field_order_no_value', $order_id)->orderBy('fdfnt.entity_id', 'asc');

$result = $query->execute();

while ($records = $result->fetchAssoc()) {
    ...
}

答案 1 :(得分:1)

Drupal 7中没有db_fetch_array(),(几乎)等效的代码将是

$sql = "select ID_Speler from TB_Spelers where uid = :uid";
$args = array(':uid' => $uid);
$row = db_query($sql, $args)->fetchObject();
$speler = $row->ID_Speler;

有关详细信息,请参阅Database API docs

答案 2 :(得分:0)

尝试这样:

 $sql = "select ID_Speler from TB_Spelers where uid = %d";
 $query = db_query($sql, $id);
 while ($records = db_fetch_array($query)) {
   $spelers[] = $records['ID_Speler'];
 }
 print_r($spelers);