本文整理汇总了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;
}