setting.php 內各資料庫的連線設定
► 連線資料庫之切換 db_set_active$databases = array( 'default' => //預設資料庫 array( 'default' => array( 'driver' => 'mysql', 'database' => 'd7', 'username' => 'username', 'password' => 'userpassword', 'host' => 'localhost', 'port' => '', 'prefix' => '', ), ), 'otherdb' => // 指定資料庫, 代號 otherdb array( 'default' => array( 'driver' => 'mysql', 'database' => 'legacydatabase', 'username' => 'legacyusername', 'password' => 'legacyuserpassword', 'host' => '122.185.22.1', 'port' => '6060', ), ), );
// 切換到指定資料庫 db_set_active('otherdb'); $result = db_query("SELECT * FROM ldap_user WHERE uid = :uid", array(':uid' => $user->uid)); // 區回預設連線 db_set_active('default');