这是我制作的一个快速类,它应该允许您使用 adoDB 连接到 3 个数据库:
class Data {
private static $_dbOne = null;
private static $_dbTwo = null;
private static $_dbThree = null;
protected function __construct() {
}
/**
* This function returns the database connection object
* @return Object Database Connection
*/
public static function dbOne() {
include_once(LIBRARY_PATH.'adodb5/adodb.inc.php');
if (null === self::$_dbOne) {
$_connOne = 'mysql://username:password@www.server.com/database';
self::$_dbOne = &ADONewConnection($_connOne);
if (self::$_dbOne==false) { die('Could not connect to the database.'); }
}
return self::$_dbOne;
}
/**
* This function returns the database connection object
* @return Object Database Connection
*/
public static function dbTwo() {
include_once(LIBRARY_PATH.'adodb5/adodb.inc.php');
if (null === self::$_dbTwo) {
$_connTwo = 'mysql://username:password@www.server.com/database';
self::$_dbTwo = &ADONewConnection($_connTwo);
if (self::$_dbTwo==false) { die('Could not connect to the database.'); }
}
return self::$_dbTwo;
}
}
/**
* This function returns the database connection object
* @return Object Database Connection
*/
public static function dbThree() {
include_once(LIBRARY_PATH.'adodb5/adodb.inc.php');
if (null === self::$_dbThree) {
$_connThree = 'mysql://username:password@www.server.com/database';
self::$_dbThree = &ADONewConnection($_connThree);
if (self::$_dbThree==false) { die('Could not connect to the database.'); }
}
return self::$_dbThree;
}
}
以下是如何使用此类的示例:
$sql = "SELECT * FROM *";
$results1 = Data::dbOne()->Execute($sql);
$results2 = Data::dbTwo()->Execute($sql);
$results3 = Data::dbThree()->Execute($sql);