mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Libs/DBSimple
* also collect sql warnings for error handling * urlescape user/password on the db connection url (mysqli://)
This commit is contained in:
@@ -19,7 +19,7 @@ class DB
|
|||||||
|
|
||||||
private static function createConnectSyntax(&$options)
|
private static function createConnectSyntax(&$options)
|
||||||
{
|
{
|
||||||
return 'mysqli://'.$options['user'].':'.$options['pass'].'@'.$options['host'].'/'.$options['db'];
|
return 'mysqli://'.urlencode($options['user']).':'.urlencode($options['pass']).'@'.$options['host'].'/'.$options['db'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function connect($idx)
|
public static function connect($idx)
|
||||||
@@ -72,10 +72,18 @@ class DB
|
|||||||
if (!error_reporting())
|
if (!error_reporting())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// continue on warning, end on error
|
||||||
|
$isError = $data['code'] > 0;
|
||||||
|
|
||||||
|
// make number sensible again
|
||||||
|
$data['code'] = abs($data['code']);
|
||||||
|
|
||||||
$error = "DB ERROR:<br /><br />\n\n<pre>".print_r($data, true)."</pre>";
|
$error = "DB ERROR:<br /><br />\n\n<pre>".print_r($data, true)."</pre>";
|
||||||
|
|
||||||
echo CLI ? strip_tags($error) : $error;
|
echo CLI ? strip_tags($error) : $error;
|
||||||
exit;
|
|
||||||
|
if ($isError)
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function logger($self, $query, $trace)
|
public static function logger($self, $query, $trace)
|
||||||
|
|||||||
@@ -163,6 +163,17 @@ class DbSimple_Mysqli extends DbSimple_Database
|
|||||||
$result = mysqli_query($this->link, $queryMain[0]);
|
$result = mysqli_query($this->link, $queryMain[0]);
|
||||||
if ($result === false)
|
if ($result === false)
|
||||||
return $this->_setDbError($queryMain[0]);
|
return $this->_setDbError($queryMain[0]);
|
||||||
|
|
||||||
|
if ($this->link->warning_count) {
|
||||||
|
if ($warn = $this->link->query("SHOW WARNINGS")) {
|
||||||
|
while ($warnRow = $warn->fetch_row())
|
||||||
|
if ($warnRow[0] !== 'Note')
|
||||||
|
$this->_setLastError(-$warnRow[1], $warnRow[2], $queryMain[0]);
|
||||||
|
|
||||||
|
$warn->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_object($result)) {
|
if (!is_object($result)) {
|
||||||
if (preg_match('/^\s* INSERT \s+/six', $queryMain[0]))
|
if (preg_match('/^\s* INSERT \s+/six', $queryMain[0]))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user