私がそれをどのように解決したか:
クラス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変数を使用します。