导航

Drupal启动阶段之三:数据库

Posted on 2013-10-11 16:02  eastson  阅读(245)  评论(0编辑  收藏  举报

Drupal在数据库启动阶段仅仅是简单地包含了database.inc文件,然后再注册类加载器:

function _drupal_bootstrap_database() {
  // Initialize the database system. Note that the connection
  // won't be initialized until it is actually requested.
  require_once DRUPAL_ROOT . '/includes/database/database.inc';

  // Register autoload functions so that we can access classes and interfaces.
  // The database autoload routine comes first so that we can load the database
  // system without hitting the database. That is especially important during
  // the install or upgrade process.
  spl_autoload_register('drupal_autoload_class');
  spl_autoload_register('drupal_autoload_interface');
}

 

为什么要在database.inc之后注册类加载器?这是因为Drupal的类加载器使用了后台数据库一个名为registry的表,在加载类时会查询该表,所以必须放在database.inc之后。关于Drupal的类加载器可以参考《Drupal如何实现类的自动加载?》。

 

必须要注意关于database.inc的这段备注:

// Initialize the database system. Note that the connection
// won't be initialized until it is actually requested.

当前数据库还没有连接,只有真正的请求到来时才会执行连接。