function __construct(array $config) { if (!isset($config['db'])) { throw new Exception(__("sqlite config error,can't found \$config['db'] value.")); } parent::__construct($config); }
function __construct(array $config) { if (!isset($config['port']) || !$config['port'] > 0) { $config['port'] = 5432; } parent::__construct($config); }
function __construct(array $config) { static $c = null; if (null === $c) { $c = version_compare(PHP_VERSION, '5.4', '<'); } if ($c) { # php5.4以下有注入漏洞,所以本系统不允许使用PDO throw new Exception(__('If use pdo Driver, need php 5.4+, because less php 5.4 has the SQL injection vulnerability.')); } if (is_array($config['connection']['hostname'])) { $pdo = current($config['connection']['hostname']); if (is_array($pdo)) { $pdo = current($pdo); } } else { $pdo = $config['connection']['hostname']; } list($type, $host) = explode(':', $pdo, 2); if (isset($config['pdo_type']) && $config['pdo_type']) { $type = strtolower($config['pdo_type']); } else { if (!$type) { throw new Exception(__('pdo config connection hostname error. need pdo driver type')); } if ($type === 'uri') { // uri:file:///path/to/dsnfile $config['connection']['hostname'] = $pdo = file_get_contents($host); list($type, $host) = explode(':', $pdo, 2); if (!$type) { throw new Exception(__('pdo :host error. need pdo driver type'), array(':host', $host)); } } $type = strtolower($type); } if (!in_array($type, Database_Driver_PDO::$_pdo_types)) { throw new Exception(__('Unknown driver type: :type'), array(':type' => $type)); } $this->_pdo_driver_type = $type; # driver option if (!isset($config['options']) || !is_array($config['options'])) { $config['options'] = array(); } if (isset($config['persistent']) && $config['persistent']) { $config['options'][PDO::ATTR_PERSISTENT] = true; } parse_str(str_replace(';', '&', $host), $ot); $default_port = null; switch ($type) { case 'ibm': case 'odbc': $db_name = 'DATABASE'; break; case 'informix': $db_name = 'database'; break; case 'sqlsrv': $db_name = 'Database'; $default_port = 1433; break; case 'mysql': $db_name = 'dbname'; $this->mysql = true; $this->_identifier = '`'; if ($config['charset']) { $options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES '{$config['charset']}';"; } $default_port = 3306; break; default: $db_name = 'dbname'; break; } if (!isset($ot[$db_name])) { if ($config['connection']['database']) { $ot[$db_name] = $config['connection']['database']; # 重新还原 $config['connection']['hostname'] = $type . ':' . http_build_query($ot, '', ';'); } } else { $config['connection']['database'] = $ot[$db_name]; } # 默认端口 if ($default_port) { if (!isset($config['connection']['port']) || !$config['connection']['port']) { $config['connection']['port'] = isset($ot['port']) && $ot['port'] ? (int) $ot['port'] : $default_port; } } parent::__construct($config); }