the connect_options variable lets you set mysqli_options, like a connection timeout
This commit is contained in:
11
db.class.php
11
db.class.php
@@ -37,6 +37,7 @@ class DB {
|
|||||||
public static $nested_transactions = false;
|
public static $nested_transactions = false;
|
||||||
public static $usenull = true;
|
public static $usenull = true;
|
||||||
public static $ssl = array('key' => '', 'cert' => '', 'ca_cert' => '', 'ca_path' => '', 'cipher' => '');
|
public static $ssl = array('key' => '', 'cert' => '', 'ca_cert' => '', 'ca_path' => '', 'cipher' => '');
|
||||||
|
public static $connect_options = array(MYSQLI_OPT_CONNECT_TIMEOUT => 30);
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
protected static $mdb = null;
|
protected static $mdb = null;
|
||||||
@@ -49,7 +50,7 @@ class DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static $variables_to_sync = array('param_char', 'named_param_seperator', 'success_handler', 'error_handler', 'throw_exception_on_error',
|
static $variables_to_sync = array('param_char', 'named_param_seperator', 'success_handler', 'error_handler', 'throw_exception_on_error',
|
||||||
'nonsql_error_handler', 'throw_exception_on_nonsql_error', 'nested_transactions', 'usenull', 'ssl');
|
'nonsql_error_handler', 'throw_exception_on_nonsql_error', 'nested_transactions', 'usenull', 'ssl', 'connect_options');
|
||||||
|
|
||||||
$db_class_vars = get_class_vars('DB'); // the DB::$$var syntax only works in 5.3+
|
$db_class_vars = get_class_vars('DB'); // the DB::$$var syntax only works in 5.3+
|
||||||
|
|
||||||
@@ -131,6 +132,7 @@ class MeekroDB {
|
|||||||
public $nested_transactions = false;
|
public $nested_transactions = false;
|
||||||
public $usenull = true;
|
public $usenull = true;
|
||||||
public $ssl = array('key' => '', 'cert' => '', 'ca_cert' => '', 'ca_path' => '', 'cipher' => '');
|
public $ssl = array('key' => '', 'cert' => '', 'ca_cert' => '', 'ca_path' => '', 'cipher' => '');
|
||||||
|
public $connect_options = array(MYSQLI_OPT_CONNECT_TIMEOUT => 30);
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
public $internal_mysql = null;
|
public $internal_mysql = null;
|
||||||
@@ -165,13 +167,18 @@ class MeekroDB {
|
|||||||
if (! $this->port) $this->port = ini_get('mysqli.default_port');
|
if (! $this->port) $this->port = ini_get('mysqli.default_port');
|
||||||
$this->current_db = $this->dbName;
|
$this->current_db = $this->dbName;
|
||||||
$mysql = new mysqli();
|
$mysql = new mysqli();
|
||||||
|
|
||||||
$connect_flags = 0;
|
$connect_flags = 0;
|
||||||
if ($this->ssl['key']) {
|
if ($this->ssl['key']) {
|
||||||
$mysql->ssl_set($this->ssl['key'], $this->ssl['cert'], $this->ssl['ca_cert'], $this->ssl['ca_path'], $this->ssl['cipher']);
|
$mysql->ssl_set($this->ssl['key'], $this->ssl['cert'], $this->ssl['ca_cert'], $this->ssl['ca_path'], $this->ssl['cipher']);
|
||||||
$connect_flags |= MYSQLI_CLIENT_SSL;
|
$connect_flags |= MYSQLI_CLIENT_SSL;
|
||||||
}
|
}
|
||||||
$mysql->real_connect($this->host, $this->user, $this->password, $this->dbName, $this->port, null, $connect_flags);
|
foreach ($this->connect_options as $key => $value) {
|
||||||
|
$mysql->options($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// suppress warnings, since we will check connect_error anyway
|
||||||
|
@$mysql->real_connect($this->host, $this->user, $this->password, $this->dbName, $this->port, null, $connect_flags);
|
||||||
|
|
||||||
if ($mysql->connect_error) {
|
if ($mysql->connect_error) {
|
||||||
$this->nonSQLError('Unable to connect to MySQL server! Error: ' . $mysql->connect_error);
|
$this->nonSQLError('Unable to connect to MySQL server! Error: ' . $mysql->connect_error);
|
||||||
|
|||||||
Reference in New Issue
Block a user