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