当前位置: 首页>>代码示例>>PHP>>正文


PHP PDO::__construct方法代码示例

本文整理汇总了PHP中PDO::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::__construct方法的具体用法?PHP PDO::__construct怎么用?PHP PDO::__construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PDO的用法示例。


在下文中一共展示了PDO::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($dsn, $username = null, $password = null, array $driver_options = null)
 {
     parent::__construct($dsn, $username, $password, $driver_options);
     $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
     $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array("PdoStatement"));
 }
开发者ID:rvilbrandt,项目名称:php-toolset,代码行数:7,代码来源:Pdo.php

示例2: __construct

 public function __construct()
 {
     global $phpbb_root_path;
     $database = $phpbb_root_path . 'store/messenger.db';
     parent::__construct('sqlite:' . $database);
     parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
开发者ID:R3gi,项目名称:phpbb-messenger,代码行数:7,代码来源:database.php

示例3: connect

 function connect()
 {
     parent::__construct('mysql:host=' . $this->DB_HOST . ';dbname=' . $this->DB_NAME, $this->DB_USER, $this->DB_PASS);
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // always disable emulated prepared statement when using the MySQL driver
     $this->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
 }
开发者ID:rayudu444,项目名称:maruthi,代码行数:7,代码来源:database.class.php

示例4: __construct

 public function __construct($dsn, $username, $password, $options = [])
 {
     $post_query = null;
     // Let's grab the DB engine
     if (strpos($dsn, ':') !== false) {
         $this->dbengine = explode(':', $dsn)[0];
     }
     // If no charset is specified, default to UTF-8
     switch ($this->dbengine) {
         case 'mysql':
             if (strpos($dsn, ';charset=') === false) {
                 $dsn .= ';charset=utf8';
             }
             break;
         case 'pgsql':
             $post_query = 'SET NAMES UNICODE';
             break;
     }
     // Let's call the parent constructor now
     parent::__construct($dsn, $username, $password, $options);
     // Let's turn off emulated prepares
     $this->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
     if (!empty($post_query)) {
         $this->query($post_query);
     }
 }
开发者ID:resonantcore,项目名称:lib,代码行数:26,代码来源:DB.php

示例5: array

 /**
  * Creates a data source instance to represent a connection to the database.
  * The first argument can either be a string DSN or an array which contains
  * the construction arguments.
  *
  * @param mixed $dsn String DSN or array of arguments (dsn, username, password)
  * @param string $username
  * @param string $password
  * @param array $driver_options
  */
 function __construct($dsn, $username = '', $password = '', $driver_options = array())
 {
     if (is_array($dsn)) {
         $args = $dsn;
         if (isset($args[0])) {
             $dsn = $args[0];
         }
         if (isset($args[1])) {
             $username = $args[1];
         }
         if (isset($args[2])) {
             $password = $args[2];
         }
         if (isset($args[3])) {
             $driver_options = $args[3];
         }
     }
     try {
         parent::__construct($dsn, $username, $password, $driver_options);
         parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $exception) {
         throw new DataSourceCouldNotConnectException($exception->getMessage(), get_defined_vars());
     }
     $this->cachePrefix = self::CACHE_PREFIX . $dsn . '::*::';
     $this->provider = $this->instantiateProvider();
 }
开发者ID:rday,项目名称:recess,代码行数:36,代码来源:PdoDataSource.class.php

示例6: __construct

 public function __construct(array $config)
 {
     $dsn = sprintf('%s:host=%s;dbname=%s', $config['dbtype'], $config['dbhost'], $config['dbname']);
     $username = isset($config['username']) ? $config['username'] : '';
     $password = isset($config['password']) ? $config['password'] : '';
     parent::__construct($dsn, $username, $password);
 }
开发者ID:itmo-it-group-305,项目名称:sergey.poliakov-blog,代码行数:7,代码来源:DB.php

示例7: __construct

 public function __construct($database)
 {
     if (is_array($database)) {
         $db_config = $database;
     } else {
         $db_config = EE::is_set('_config', 'databases', $database) ? EE::get('_config', 'databases', $database) : false;
     }
     if (!$db_config) {
         trigger_error('No database config of ' . $database . ' found', E_USER_WARNING);
     }
     if (!isset($db_config['dsn'])) {
         trigger_error('No database dsn config of ' . $database . ' found', E_USER_WARNING);
     }
     $extension = substr($db_config['dsn'], 0, strpos($db_config['dsn'], ':'));
     if (!in_array($extension, PDO::getAvailableDrivers())) {
         trigger_error('PDO extension of ' . $extension . ' could not be found', E_USER_WARNING);
     }
     $instance = null;
     $username = isset($db_config['username']) ? $db_config['username'] : null;
     $password = isset($db_config['password']) ? $db_config['password'] : null;
     $params = isset($db_config['params']) ? $db_config['params'] : null;
     try {
         $instance = parent::__construct($db_config['dsn'], $username, $password, $params);
     } catch (PDOException $e) {
         trigger_error('Could not connect to database ' . $database . ': ' . $e->getMessage(), E_USER_ERROR);
     }
     return $instance;
 }
开发者ID:kokareff,项目名称:easyembed,代码行数:28,代码来源:db_pdo.php

示例8: __construct

 public function __construct($connConfigName = 'default')
 {
     if (!isset(self::$arrConnConfig[$connConfigName])) {
         throw new Exception("JPDO Exception : connConfigName '{$connConfigName}' does not exist!");
     }
     $connConfig = self::$arrConnConfig[$connConfigName];
     if (!isset($connConfig['dsn'])) {
         throw new Exception("JPDO Exception : in connConfig '{$connConfigName}', 'dsn' should has been set!");
     }
     if (!isset($connConfig['user'])) {
         throw new Exception("JPDO Exception : in connConfig '{$connConfigName}', 'user' should has been set!");
     }
     if (!isset($connConfig['password'])) {
         throw new Exception("JPDO Exception : in connConfig '{$connConfigName}', 'password' should has been set!");
     }
     $attr = array();
     if (isset($connConfig['persistent_connection']) && $connConfig['persistent_connection'] == 'Y') {
         $attr[PDO::ATTR_PERSISTENT] = true;
         $attr[PDO::ATTR_AUTOCOMMIT] = true;
     }
     try {
         @parent::__construct($connConfig['dsn'], $connConfig['user'], $connConfig['password'], $attr);
     } catch (PDOException $e) {
         print "DB Error: " . $e->getMessage() . "<br />";
     }
     $this->query("SET NAMES 'utf8';");
 }
开发者ID:AuTiMoThY,项目名称:Dfocus-concord-php,代码行数:27,代码来源:JPDO.inc.php

示例9: connect

 /**
  * Connect to database
  *
  * @return $this
  */
 public function connect()
 {
     parent::__construct($this->dsn, $this->username, $this->password, $this->options);
     $this->execute('SET NAMES UTF8');
     $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     return $this;
 }
开发者ID:ukrcms,项目名称:ukrcms,代码行数:12,代码来源:Db.php

示例10: __construct

 public function __construct($dsn, $username = null, $passwd = null, $options = null)
 {
     parent::__construct($dsn, $username, $passwd, $options);
     $this->listeners = new \ArrayObject();
     $this->muteListeners = false;
     $this->transactionName = null;
 }
开发者ID:timesplinter,项目名称:tsfw-db,代码行数:7,代码来源:DB.php

示例11:

 function __construct($user, $pass, $host, $dbname)
 {
     $engine = 'mysql';
     $host = 'localhost';
     $dns = $engine . ':dbname=' . $dbname . ";host=" . $host;
     parent::__construct($dns, $user, $pass);
 }
开发者ID:CodeTN-WRR,项目名称:roommate.finder,代码行数:7,代码来源:Connection.php

示例12: conecta

 private function conecta()
 {
     if (!$this->conectado) {
         parent::__construct(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
         $this->conectado = true;
     }
 }
开发者ID:JoaoAlisson,项目名称:positiv-framework,代码行数:7,代码来源:Pdo.php

示例13: __construct

 public function __construct($dsn = null, $username = null, $password = null, array $driver_options = null)
 {
     // Get the System DB Config
     global $databaseConfig;
     // Make the config easier to work with
     $conf = (object) $databaseConfig;
     // fix for sqlite dbs
     $type = strtolower(str_replace('Database', '', $conf->type));
     if ($type == 'sqlitepdo') {
         $type = 'sqlite';
     }
     // DSN
     if (!$dsn) {
         $dsn = $type . ':' . 'host=' . $conf->server . ';' . 'dbname=' . $conf->database;
     }
     // Authentication
     if (!$username) {
         $username = $conf->username;
     }
     if (!$password) {
         $password = $conf->password;
     }
     // Connect
     parent::__construct($dsn, $username, $password, $driver_options);
 }
开发者ID:helpfulrobot,项目名称:azt3k-abc-silverstripe,代码行数:25,代码来源:AbcDB.php

示例14: __construct

 public function __construct($host, $dbName, $user, $pass, ErrorHandler $errorHandler, $dbType = 'mysql')
 {
     $this->errorHandler = $errorHandler;
     parent::__construct($dbType . ':host=' . $host . ';dbname=' . $dbName, $user, $pass);
     // Throw an exception in case of an error
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
开发者ID:asalov,项目名称:vehicles_network,代码行数:7,代码来源:DB.php

示例15: __construct

 public function __construct()
 {
     if (self::$dsn === null) {
         throw new DatabaseException('Booya\\DatabaseException: dsn not configured.');
     }
     parent::__construct(self::$dsn, self::$username, self::$password, array(self::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", self::ATTR_EMULATE_PREPARES => false, self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION));
 }
开发者ID:Kekos,项目名称:booya-database,代码行数:7,代码来源:PDO.php


注:本文中的PDO::__construct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。