當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Conn::Connect方法代碼示例

本文整理匯總了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;
 }
開發者ID:Giselly,項目名稱:GPDev,代碼行數:18,代碼來源:Conn.class.php

示例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;
 }
開發者ID:Aberos,項目名稱:OTPANEL,代碼行數:19,代碼來源:Conn.class.php

示例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;
 }
開發者ID:arthurleon,項目名稱:ytradio,代碼行數:20,代碼來源:Conn.class.php

示例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;
 }
開發者ID:jhonlennon,項目名稱:estrutura-mvc,代碼行數:26,代碼來源:Conn.class.php


注:本文中的Conn::Connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。