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


PHP pdo::__construct方法代碼示例

本文整理匯總了PHP中pdo::__construct方法的典型用法代碼示例。如果您正苦於以下問題:PHP pdo::__construct方法的具體用法?PHP pdo::__construct怎麽用?PHP pdo::__construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pdo的用法示例。


在下文中一共展示了pdo::__construct方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param array $config
  */
 public function __construct($config)
 {
     $_alldbtype = array('mysql', 'pgsql', 'mssql', 'sybase', 'dblib');
     $driver_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
     if (in_array($config['dbtype'], $_alldbtype)) {
         $dsn = $config['dbtype'] . ':dbname=' . $config['dbname'] . ';host=' . $config['dbhost'] . ';charset=' . $config['charset'];
         if (!empty($config['dbport'])) {
             $dsn .= ';port=' . $config['dbport'];
         }
         $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
     } elseif ($config['dbtype'] == 'oci') {
         $dsn = 'oci:dbname=//' . $config['dbhost'] . ':' . $config['dbport'] . '/' . $config['dbname'] . ';charset=AL32UTF8';
         $driver_options[PDO::ATTR_STRINGIFY_FETCHES] = true;
     } elseif ($config['dbtype'] == 'sqlite') {
         $dsn = 'sqlite:' . $config['dbname'];
     } else {
         trigger_error($config['dbtype'] . ' is not supported', 256);
     }
     $this->server = $config['dbhost'];
     $this->dbtype = $config['dbtype'];
     $this->dbname = $config['dbname'];
     $this->user = $config['dbuname'];
     try {
         parent::__construct($dsn, $config['dbuname'], $config['dbpass'], $driver_options);
         parent::exec("SET SESSION time_zone='" . NV_SITE_TIMEZONE_GMT_NAME . "'");
         $this->connect = 1;
     } catch (PDOException $e) {
         trigger_error($e->getMessage());
     }
 }
開發者ID:nukeviet,項目名稱:nukeviet,代碼行數:33,代碼來源:Database.php

示例2: __construct

 public function __construct()
 {
     $this->dbtype = 'mysql';
     $this->host = 'localhost';
     $this->user = 'root';
     $this->pass = '';
     $this->database = 'mks';
     $dns = $this->dbtype . ':dbname=' . $this->database . ";host=" . $this->host;
     parent::__construct($dns, $this->user, $this->pass);
 }
開發者ID:gummybites,項目名稱:mks,代碼行數:10,代碼來源:config2.php

示例3:

 function __construct()
 {
     parent::__construct(DB_TYPE . ":host=" . DB_HOST . ";dbname=" . DB, DB_USER, DB_PASS);
 }
開發者ID:GlennWatt,項目名稱:personalWebSpace,代碼行數:4,代碼來源:database.php


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