/** * Implement the singleton pattern, using a static accessor. * * @param string $DBHOST * @param string $DBPORT * @param string $DBNAME * @param string $DBUSER * @param string $DBPASS * * @throws Exception */ public static function createInstance($DBHOST, $DBPORT, $DBNAME, $DBUSER, $DBPASS) { if (self::$pdo instanceof PDO) { throw new Exception('WT_DB::createInstance() can only be called once.'); } // Create the underlying PDO object self::$pdo = new PDO(substr($DBHOST, 0, 1) == '/' ? "mysql:unix_socket={$DBHOST};dbname={$DBNAME}" : "mysql:host={$DBHOST};dbname={$DBNAME};port={$DBPORT}", $DBUSER, $DBPASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_AUTOCOMMIT => true)); self::$pdo->exec("SET NAMES UTF8"); self::$instance = new self(); }