function __construct($config) { mysqli_report(MYSQLI_REPORT_ERROR); $this->cfg = array_merge($this->cfg, $config); if (preg_match('#^(.*)?:(\\d+)?$#D', $this->cfg['host'], $match)) { $this->cfg['host'] = empty($match[1]) ? null : $match[1]; $this->cfg['port'] = empty($match[2]) ? null : $match[2]; } if (!$this->cfg['socket']) { $this->cfg['socket'] = null; } if (!is_int($this->cfg['flags'])) { $this->cfg['flags'] = null; } if (!is_array($this->cfg['options'])) { $this->cfg['options'] = array(); } parent::init(); foreach ($this->cfg['options'] as $option => $value) { if (!parent::options($option, $value)) { throw new Exception($this->error, $this->errno); } } $ssl =& $this->cfg['ssl']; if ($ssl['key'] || $ssl['cert'] || $ssl['ca'] || $ssl['capath'] || $ssl['cipher']) { # bugs.php.net/bug.php?id=51026 & bugs.php.net/bug.php?id=37620 if (version_compare(phpversion(), '5.3.0', '>=') && version_compare(phpversion(), '5.3.3', '<')) { throw new Exception('MySQLi SSL not available due to PHP bug 51026'); } parent::ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], $ssl['capath'], $ssl['cipher']); } $this->connect(); }
private function init() { $handle = new MySQLi(); $handle->init(); $handle->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); if (@$handle->real_connect(_DBMS_HOST, _DBMS_LOGIN, _DBMS_PASS, _DBMS_DB) === FALSE) { throw new DatabaseException($handle->connect_error); } if (!$handle->select_db(_DBMS_DB)) { throw new DatabaseException('Can\'t connect to Database !'); } return $handle; }
function __construct() { parent::init(); }