本文整理汇总了PHP中DBConnection::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::connection方法的具体用法?PHP DBConnection::connection怎么用?PHP DBConnection::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection::connection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
private final function __construct()
{
try {
$a = Application::getAppInfo();
self::$connection = new PDO("mysql:host=" . $a->GetDBHost() . ";dbname=" . $a->GetDBName(), $a->GetDBUser(), $a->GetDBPass());
} catch (PDOException $e) {
throw new Exception("Impossible to establish connection to DB");
}
}
示例2: getConnection
/**
consider making private (which forces you to use executeSQLSelect() and executeSQLCommand()
*/
public static function getConnection()
{
if (self::$connection === null) {
self::$connection = new PDO('mysql:host=localhost;port=3307;dbname=gtlol', 'gtloladmin', 'poppy');
return new PDO('mysql:host=localhost;port=3307;dbname=gtlol', 'gtloladmin', 'poppy');
} else {
return self::$connection;
}
}
示例3: getConnection
/**
* Returns a PDO object for a connection to the database
*
* @return PDO
*
*/
public static function getConnection()
{
// Credentials for the DB
require UTIL_DB_CREDS;
// Only complete if the connection does not exist
if (self::$connection === null) {
try {
// Create the DB connection
self::$connection = new PDO($dsn, $user, $pass);
# Fires exceptions. Use try/catch with this
self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
die;
}
}
return self::$connection;
}