Drupal 7 Module Development – Liveblogging from Drupal Camp NYC 8

List of Changes

Converting 6.x modules to 7.x – Categorical

New Database API

  • Vendor-agnostic abstraction layer
  • Built on top of PHP’s PDO library
  • Current drivers: MySQL, PostgreSQL, SQLite, SQL Server
  • Can still write SQL. Example: $result = db_query(“SELECT nid, tilte FROM {node}”);
  • Placeholders have changed. Strings don’t have to be enclosed in single quotes any more, the Drupal database abstraction layer does that for you. Example:
    $sql = “SELECT title FROM {node} WHERE type = :type”;
    $result = db_query($sql, array(‘:type’ => ‘page’));
  • Results sets from select queries are easier to loop over (e.g. with a foreach ($result as $record) { // do stuff }.
  • Dynamic Queries possible. Example too complicated to note down in 1 minute.

hook calls

  • hook_nodeapi: no more $op
  • Replace with several individual hooks
  • Same for hook_user and hook_blocks