mirror of
https://github.com/dg/dibi.git
synced 2025-08-15 18:44:27 +02:00
bugfix, enhanced error reporting, better examples
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* @license GNU GENERAL PUBLIC LICENSE version 2
|
||||
* @package dibi
|
||||
* @category Database
|
||||
* @version 0.8 (Revision: $WCREV$, Date: $WCDATE$)
|
||||
* @version 0.8b (Revision: $WCREV$, Date: $WCDATE$)
|
||||
*/
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
|
||||
define('DIBI', '0.8 (Revision: $WCREV$, Date: $WCDATE$)');
|
||||
define('DIBI', '0.8b (Revision: $WCREV$, Date: $WCDATE$)');
|
||||
|
||||
|
||||
if (version_compare(PHP_VERSION , '5.0.3', '<'))
|
||||
@@ -240,7 +240,10 @@ class dibi
|
||||
*/
|
||||
static public function query($args)
|
||||
{
|
||||
$args = func_get_args();
|
||||
// receive arguments
|
||||
if (!is_array($args))
|
||||
$args = func_get_args();
|
||||
|
||||
return self::getConnection()->query($args);
|
||||
}
|
||||
|
||||
|
@@ -80,7 +80,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
|
||||
if (!is_resource($conn))
|
||||
throw new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error (driver mysql)'", array(
|
||||
'message' => mysql_error() ? mysql_error() : $php_errormsg,
|
||||
'code' => mysql_errno(),
|
||||
));
|
||||
@@ -94,7 +94,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
|
||||
if (!empty($config['database'])) {
|
||||
if (!@mysql_select_db($config['database'], $conn))
|
||||
throw new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error (driver mysql)", array(
|
||||
'message' => mysql_error($conn),
|
||||
'code' => mysql_errno($conn),
|
||||
));
|
||||
|
@@ -65,7 +65,7 @@ class DibiMySqliDriver extends DibiDriver
|
||||
$conn = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
|
||||
if (!$conn)
|
||||
throw new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error (driver mysqli)", array(
|
||||
'message' => mysqli_connect_error(),
|
||||
'code' => mysqli_connect_errno(),
|
||||
));
|
||||
|
@@ -48,13 +48,13 @@ class DibiOdbcDriver extends DibiDriver
|
||||
if (empty($config['database'])) $config['database'] = ini_get('odbc.default_db');
|
||||
|
||||
if (empty($config['username']))
|
||||
throw new DibiException("Username must be specified");
|
||||
throw new DibiException("Username must be specified (driver odbc)");
|
||||
|
||||
if (empty($config['password']))
|
||||
throw new DibiException("Password must be specified");
|
||||
throw new DibiException("Password must be specified (driver odbc)");
|
||||
|
||||
if (empty($config['database']))
|
||||
throw new DibiException("Database must be specified");
|
||||
throw new DibiException("Database must be specified (driver odbc)");
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class DibiOdbcDriver extends DibiDriver
|
||||
$conn = @odbc_pconnect($config['database'], $config['username'], $config['password']);
|
||||
|
||||
if (!is_resource($conn))
|
||||
throw new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error (driver odbc)", array(
|
||||
'message' => odbc_errormsg(),
|
||||
'code' => odbc_error(),
|
||||
));
|
||||
@@ -177,7 +177,7 @@ class DibiOdbcDriver extends DibiDriver
|
||||
if ($limit >= 0)
|
||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')';
|
||||
|
||||
if ($offset) throw new DibiException('Offset is not implemented.');
|
||||
if ($offset) throw new DibiException('Offset is not implemented in driver odbc');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -42,7 +42,7 @@ class DibiPdoDriver extends DibiDriver
|
||||
throw new DibiException("PHP extension 'pdo' is not loaded");
|
||||
|
||||
if (empty($config['dsn']))
|
||||
throw new DibiException("DSN must be specified");
|
||||
throw new DibiException("DSN must be specified (driver odbc)");
|
||||
|
||||
if (empty($config['username'])) $config['username'] = NULL;
|
||||
if (empty($config['password'])) $config['password'] = NULL;
|
||||
|
@@ -43,7 +43,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
throw new DibiException("PHP extension 'pgsql' is not loaded");
|
||||
|
||||
if (empty($config['string']))
|
||||
throw new DibiException("Connection string must be specified");
|
||||
throw new DibiException("Connection string must be specified (driver postgre)");
|
||||
|
||||
if (empty($config['type'])) $config['type'] = NULL;
|
||||
|
||||
@@ -62,7 +62,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
$conn = @pg_pconnect($config['string'], $config['type']);
|
||||
|
||||
if (!is_resource($conn))
|
||||
throw new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error (driver postgre)", array(
|
||||
'message' => pg_last_error(),
|
||||
));
|
||||
|
||||
|
@@ -44,7 +44,7 @@ class DibiSqliteDriver extends DibiDriver
|
||||
throw new DibiException("PHP extension 'sqlite' is not loaded");
|
||||
|
||||
if (empty($config['database']))
|
||||
throw new DibiException("Database must be specified");
|
||||
throw new DibiException("Database must be specified (driver sqlite)");
|
||||
|
||||
if (!isset($config['mode']))
|
||||
$config['mode'] = 0666;
|
||||
@@ -65,7 +65,7 @@ class DibiSqliteDriver extends DibiDriver
|
||||
$conn = @sqlite_popen($config['database'], $config['mode'], $errorMsg);
|
||||
|
||||
if (!$conn)
|
||||
throw new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error (driver sqlite)", array(
|
||||
'message' => $errorMsg,
|
||||
));
|
||||
|
||||
|
@@ -123,13 +123,14 @@ abstract class DibiDriver
|
||||
dibi::log(
|
||||
"ERROR: $info[message]"
|
||||
. "\n-- SQL: " . $sql
|
||||
. "\n-- driver: " . $this->config['driver']
|
||||
. ";\n-- " . date('Y-m-d H:i:s ')
|
||||
);
|
||||
}
|
||||
|
||||
if (dibi::$throwExceptions) {
|
||||
$info = $this->errorInfo();
|
||||
throw new DibiException('Query error', $info, $sql);
|
||||
throw new DibiException('Query error (driver ' . $this->config['driver'] . ')', $info, $sql);
|
||||
} else {
|
||||
$info = $this->errorInfo();
|
||||
if ($info['code']) $info['message'] = "[$info[code]] $info[message]";
|
||||
@@ -146,6 +147,7 @@ abstract class DibiDriver
|
||||
"OK: " . $sql
|
||||
. ";\n-- result: $msg"
|
||||
. "\n-- takes: " . sprintf('%0.3f', $timer * 1000) . ' ms'
|
||||
. "\n-- driver: " . $this->config['driver']
|
||||
. "\n-- " . date('Y-m-d H:i:s ')
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user