我是如何解决的:
类 MyDB {
private static $db;
static public function getInstance($Start = false) {
if ($_SERVER['SERVER_NAME'] == 'localhost') {
/* $DB_HOST = 'localhost';
$DB_DATABASE = '';
$DB_USER = '';
$DB_PASSWORD = '';
*/
$aConnection = array('DB_HOST' => 'localhost', 'DB_DATABASE' => '', 'DB_USER' => '', 'DB_PASSWORD' => '');
} else {
$aConnection = array('DB_HOST' => 'd', 'DB_DATABASE' => '', 'DB_USER' => '', 'DB_PASSWORD' => $DB_PASSWORD);
}
if (!self::$db) {
self::$db = new PDO('mysql:host=' . $aConnection['DB_HOST'] . ';dbname=' . $aConnection['DB_DATABASE'] , $aConnection['DB_USER'], $aConnection['DB_PASSWORD'], array(PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
}
echo mysql_error();
if ($Start)
return $aConnection;
else #Normale pdo klasse
return self::$db;
}
}
所以如果我需要一个正常的mysql连接,我使用数组,如果我需要PDO,我使用静态db变量。