2

I've an issue with a migration from a drupal 6 to 7 website. I'm a beginner in PHP and MySQL and I can't find a solution to my problem.

The code I'm struggling with is following:

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

I always get a "Call to undefined function db_fetch_array()"

Any help is very much appreciated.

1

3 Answers 3

2

Use this in 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()) {
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

1

There's no db_fetch_array() in Drupal 7, the (almost) equivalent code would be

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

See the Database API docs for more info.

Comments

0

Try like that:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.