コード例 #1
0
ファイル: Database.php プロジェクト: nukeviet/nukeviet
 /**
  * @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());
     }
 }
コード例 #2
0
ファイル: config2.php プロジェクト: gummybites/mks
 public function __construct()
 {
     $this->dbtype = 'mysql';
     $this->host = 'localhost';
     $this->user = '******';
     $this->pass = '';
     $this->database = 'mks';
     $dns = $this->dbtype . ':dbname=' . $this->database . ";host=" . $this->host;
     parent::__construct($dns, $this->user, $this->pass);
 }
コード例 #3
0
 function __construct()
 {
     parent::__construct(DB_TYPE . ":host=" . DB_HOST . ";dbname=" . DB, DB_USER, DB_PASS);
 }