本文整理匯總了PHP中Conn::Connect方法的典型用法代碼示例。如果您正苦於以下問題:PHP Conn::Connect方法的具體用法?PHP Conn::Connect怎麽用?PHP Conn::Connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Conn
的用法示例。
在下文中一共展示了Conn::Connect方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: conectar
/**
* Conecta com o banco de dados com o pattern singleton.
* Retorna um objeto PDO!
*/
private static function conectar()
{
try {
if (self::$Connect == null) {
$dsn = 'mysql:host=' . self::$Host . ';dbname=' . self::$Dbsa;
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8');
self::$Connect = new PDO($dsn, self::$User, self::$Pass, $options);
}
} catch (PDOException $e) {
die($e->getMessage());
}
self::$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$Connect;
}
示例2: Conectar
/**
* Conecta com o banco de dados com o pattern singleton.
* Retorna um objeto PDO!
*/
private static function Conectar()
{
try {
if (self::$Connect == null) {
$dsn = 'mysql:host=' . self::$Host . ';dbname=' . self::$Dbsa;
$options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES latin1'];
self::$Connect = new PDO($dsn, self::$User, self::$Pass, $options);
}
} catch (PDOException $e) {
PHPErro($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
die;
}
self::$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$Connect;
}
示例3: ConnectDB
/**
* Connects to the database using Singleton.
* Returns a PDO object.
*/
private static function ConnectDB()
{
try {
if (self::$Connect == null) {
//dsn define qual o DB a ser usado. No caso estamos usando o MySQL.
$dsn = 'mysql:host=' . self::$Host . ';dbname=' . self::$Dbsa;
$options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
self::$Connect = new PDO($dsn, self::$User, self::$Pass, $options);
}
} catch (PDOException $e) {
PHPError($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
die;
}
self::$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$Connect;
}
示例4: Conectar
/**
* Iniciar uma conexão com o banco de dados e retorna um objeto PDO.
* @return PDO
*/
private static function Conectar()
{
try {
if (self::$Connect == null) {
if (!self::$Config) {
self::$Config = get_config('db' . (IS_LOCAL ? '-local' : null));
}
$dsn = 'mysql:host=' . self::$Config['host'] . ';dbname=' . self::$Config['database'] . ';charset=utf8';
$options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
self::$Connect = new PDO($dsn, self::$Config['user'], self::$Config['password'], $options);
self::$Connect->exec('SET NAMES utf8');
self::$Connect->exec('SET CHARACTER SET utf8');
self::$Connect->exec('SET time_zone = \'' . date_default_timezone_get() . '\'');
}
} catch (PDOException $e) {
throw new Exception('Não foi possível conectar a base de dados.');
} catch (Exception $e) {
throw new Exception('Não foi possível conectar a base de dados.');
}
self::$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$Connect;
}