Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Drupal 7 has brought a lot of changes for developers. One of the biggest changes is Drupal 7's new database API. An object-oriented system implemented developers.
The new database API is built with PHP's native PDO engine. Take a look at the following example:
<?php
/* Drupal 6 query */
$sql = "SELECT n.nid, n.title, n.uid FROM {node} n WHERE n.type = 'article'";
$results = db_query_range($sql, 0, 50);
/* Drupal 7 query */
$query = db_select('node', 'n');
$query->condition('n.type', 'article', '=')
->fields('n', array('nid', 'title', 'uid'))
->range(0, 50);
$result = $query->execute();
?>