4 Commits
dev ... master

Author SHA1 Message Date
Sergey Tsalkov
ed0b6f040d DB::$ssl now works even if DB::$ssl['key'] is NULL
DB::$connect_flags allows access to flags passed to $mysqli->real_connect()

Resolves #82
Resolves #83
2022-03-24 16:58:37 +00:00
Sergey Tsalkov
f82f0cc208 add another queryWalk() test case
make sure we're using $is_buffered=false for queryWalk() like we're supposed to
2021-08-14 05:08:41 +00:00
Sergey Tsalkov
7febdbd1f5 since queryRaw() is deprecated, it was a mistake to change its behavior
return it to using $is_buffered=true, and restore queryRawUnbuf() for $is_buffered=false
both queryRaw() and queryRawUnbuf() are deprecated, and it's recommended that you use queryWalk() instead
2021-08-14 05:02:27 +00:00
Sergey Tsalkov
57b7527a46 fix bug in columnList(), add test 2021-08-08 14:15:19 +00:00
3 changed files with 37 additions and 10 deletions

View File

@@ -31,13 +31,14 @@ class DB {
public static $param_char = '%'; public static $param_char = '%';
public static $named_param_seperator = '_'; public static $named_param_seperator = '_';
public static $nested_transactions = false; public static $nested_transactions = false;
public static $ssl = array('key' => '', 'cert' => '', 'ca_cert' => '', 'ca_path' => '', 'cipher' => ''); public static $ssl = null;
public static $connect_options = array(MYSQLI_OPT_CONNECT_TIMEOUT => 30); public static $connect_options = array(MYSQLI_OPT_CONNECT_TIMEOUT => 30);
public static $connect_flags = 0;
public static $logfile; public static $logfile;
// internal // internal
protected static $mdb = null; protected static $mdb = null;
public static $variables_to_sync = array('param_char', 'named_param_seperator', 'nested_transactions', 'ssl', 'connect_options', 'logfile'); public static $variables_to_sync = array('param_char', 'named_param_seperator', 'nested_transactions', 'ssl', 'connect_options', 'connect_flags', 'logfile');
public static function getMDB() { public static function getMDB() {
$mdb = DB::$mdb; $mdb = DB::$mdb;
@@ -83,8 +84,9 @@ class MeekroDB {
public $param_char = '%'; public $param_char = '%';
public $named_param_seperator = '_'; public $named_param_seperator = '_';
public $nested_transactions = false; public $nested_transactions = false;
public $ssl = array('key' => '', 'cert' => '', 'ca_cert' => '', 'ca_path' => '', 'cipher' => ''); public $ssl = null;
public $connect_options = array(MYSQLI_OPT_CONNECT_TIMEOUT => 30); public $connect_options = array(MYSQLI_OPT_CONNECT_TIMEOUT => 30);
public $connect_flags = 0;
public $logfile; public $logfile;
// internal // internal
@@ -142,11 +144,15 @@ class MeekroDB {
$this->current_db = $this->dbName; $this->current_db = $this->dbName;
$mysql = new mysqli(); $mysql = new mysqli();
$connect_flags = 0; $connect_flags = $this->connect_flags;
if ($this->ssl['key']) { if (is_array($this->ssl)) {
$mysql->ssl_set($this->ssl['key'], $this->ssl['cert'], $this->ssl['ca_cert'], $this->ssl['ca_path'], $this->ssl['cipher']); // PHP produces a warning when trying to access undefined array keys
$ssl_default = array('key' => NULL, 'cert' => NULL, 'ca_cert' => NULL, 'ca_path' => NULL, 'cipher' => NULL);
$ssl = array_merge($ssl_default, $this->ssl);
$mysql->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca_cert'], $ssl['ca_path'], $ssl['cipher']);
$connect_flags |= MYSQLI_CLIENT_SSL; $connect_flags |= MYSQLI_CLIENT_SSL;
} }
foreach ($this->connect_options as $key => $value) { foreach ($this->connect_options as $key => $value) {
$mysql->options($key, $value); $mysql->options($key, $value);
} }
@@ -486,7 +492,7 @@ class MeekroDB {
$columns[$row['Field']] = array( $columns[$row['Field']] = array(
'type' => $row['Type'], 'type' => $row['Type'],
'null' => $row['Null'], 'null' => $row['Null'],
'key' => $row['Type'], 'key' => $row['Key'],
'default' => $row['Default'], 'default' => $row['Default'],
'extra' => $row['Extra'] 'extra' => $row['Extra']
); );
@@ -778,9 +784,10 @@ class MeekroDB {
$opts_fullcols = (isset($opts['fullcols']) && $opts['fullcols']); $opts_fullcols = (isset($opts['fullcols']) && $opts['fullcols']);
$opts_raw = (isset($opts['raw']) && $opts['raw']); $opts_raw = (isset($opts['raw']) && $opts['raw']);
$opts_unbuf = (isset($opts['unbuf']) && $opts['unbuf']);
$opts_assoc = (isset($opts['assoc']) && $opts['assoc']); $opts_assoc = (isset($opts['assoc']) && $opts['assoc']);
$opts_walk = (isset($opts['walk']) && $opts['walk']); $opts_walk = (isset($opts['walk']) && $opts['walk']);
$is_buffered = !($opts_raw || $opts_walk); $is_buffered = !($opts_unbuf || $opts_walk);
list($query, $args) = $this->runHook('pre_parse', array('query' => $query, 'args' => $args)); list($query, $args) = $this->runHook('pre_parse', array('query' => $query, 'args' => $args));
$sql = call_user_func_array(array($this, 'parse'), array_merge(array($query), $args)); $sql = call_user_func_array(array($this, 'parse'), array_merge(array($query), $args));
@@ -898,6 +905,7 @@ class MeekroDB {
} }
public function queryRaw() { return $this->queryHelper(array('raw' => true), func_get_args()); } public function queryRaw() { return $this->queryHelper(array('raw' => true), func_get_args()); }
public function queryRawUnbuf() { return $this->queryHelper(array('raw' => true, 'unbuf' => true), func_get_args()); }
public function queryOneList() { return call_user_func_array(array($this, 'queryFirstList'), func_get_args()); } public function queryOneList() { return call_user_func_array(array($this, 'queryFirstList'), func_get_args()); }
public function queryOneRow() { return call_user_func_array(array($this, 'queryFirstRow'), func_get_args()); } public function queryOneRow() { return call_user_func_array(array($this, 'queryFirstRow'), func_get_args()); }

View File

@@ -279,7 +279,10 @@ class BasicTest extends SimpleTest {
$columns = DB::columnList('store data'); $columns = DB::columnList('store data');
$this->assert(count($columns) === 2); $this->assert(count($columns) === 2);
$this->assert($columns['picture']['type'] === 'blob'); $this->assert($columns['picture']['type'] === 'blob');
$this->assert($columns['picture']['null'] === 'YES');
$this->assert($columns['picture']['key'] === '');
$this->assert($columns['picture']['default'] === NULL);
$this->assert($columns['picture']['extra'] === '');
$smile = file_get_contents(__DIR__ . '/smile1.jpg'); $smile = file_get_contents(__DIR__ . '/smile1.jpg');
DB::insert('store data', array( DB::insert('store data', array(

View File

@@ -45,4 +45,20 @@ class WalkTest extends SimpleTest {
// if $Walk hasn't been properly freed, this will produce an out of sync error // if $Walk hasn't been properly freed, this will produce an out of sync error
DB::query("SELECT * FROM accounts"); DB::query("SELECT * FROM accounts");
} }
function test_5_walk_error() {
$Walk = DB::queryWalk("SELECT * FROM accounts");
$Walk->next();
try {
// this will produce an out of sync error
DB::query("SELECT * FROM accounts");
} catch (MeekroDBException $e) {
if (substr_count($e->getMessage(), 'out of sync')) {
$exception_was_caught = 1;
}
}
$this->assert($exception_was_caught === 1);
}
} }