本文整理匯總了PHP中Factory::dbHandler方法的典型用法代碼示例。如果您正苦於以下問題:PHP Factory::dbHandler方法的具體用法?PHP Factory::dbHandler怎麽用?PHP Factory::dbHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Factory
的用法示例。
在下文中一共展示了Factory::dbHandler方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createOrGetDBHandler
public static function createOrGetDBHandler()
{
if (!isset(self::$dbHandler)) {
try {
$pdoOptions[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
self::$dbHandler = new PDO('mysql:host=' . self::$hostName . ';dbname=' . self::$dbName, self::$username, self::$password, $pdoOptions);
} catch (PDOException $e) {
echo "Error while connecting to database:" . PHP_EOL;
die($e->getMessage());
}
}
return self::$dbHandler;
}
示例2: createOrGetDBHandler
public static function createOrGetDBHandler()
{
if (!isset(self::$dbHandler)) {
// Overwrite settings with OpenShift
if (getenv('OPENSHIFT_APP_NAME') !== false) {
self::$dbName = getenv('OPENSHIFT_APP_NAME');
self::$hostName = getenv('OPENSHIFT_MYSQL_DB_HOST');
self::$port = getenv('OPENSHIFT_MYSQL_DB_PORT');
self::$username = getenv('OPENSHIFT_MYSQL_DB_USERNAME');
self::$password = getenv('OPENSHIFT_MYSQL_DB_PASSWORD');
}
$pdoOptions[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
self::$dbHandler = new PDO('mysql:host=' . self::$hostName . ';port=' . self::$port . ';dbname=' . self::$dbName, self::$username, self::$password, $pdoOptions);
}
return self::$dbHandler;
}