当前位置: 首页>>代码示例>>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;未经允许,请勿转载。