mirror of
https://github.com/dg/dibi.git
synced 2025-08-16 02:54:25 +02:00
throwing exception on connect
This commit is contained in:
@@ -42,11 +42,12 @@ class DibiMySqlDriver extends DibiDriver {
|
||||
|
||||
/**
|
||||
* Driver factory
|
||||
* @throw DibiException
|
||||
*/
|
||||
public static function connect($config)
|
||||
{
|
||||
if (!extension_loaded('mysql'))
|
||||
return new DibiException("PHP extension 'mysql' is not loaded");
|
||||
throw new DibiException("PHP extension 'mysql' is not loaded");
|
||||
|
||||
foreach (array('username', 'password', 'protocol') as $var)
|
||||
if (!isset($config[$var])) $config[$var] = NULL;
|
||||
@@ -73,7 +74,7 @@ class DibiMySqlDriver extends DibiDriver {
|
||||
|
||||
|
||||
if (!is_resource($conn))
|
||||
return new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error", array(
|
||||
'message' => mysql_error() ? mysql_error() : $php_errormsg,
|
||||
'code' => mysql_errno(),
|
||||
));
|
||||
@@ -87,7 +88,7 @@ class DibiMySqlDriver extends DibiDriver {
|
||||
|
||||
if (!empty($config['database'])) {
|
||||
if (!@mysql_select_db($config['database'], $conn))
|
||||
return new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error", array(
|
||||
'message' => mysql_error($conn),
|
||||
'code' => mysql_errno($conn),
|
||||
));
|
||||
|
@@ -44,7 +44,7 @@ class DibiMySqliDriver extends DibiDriver {
|
||||
public static function connect($config)
|
||||
{
|
||||
if (!extension_loaded('mysqli'))
|
||||
return new DibiException("PHP extension 'mysqli' is not loaded");
|
||||
throw new DibiException("PHP extension 'mysqli' is not loaded");
|
||||
|
||||
if (empty($config['host'])) $config['host'] = 'localhost';
|
||||
|
||||
@@ -54,7 +54,7 @@ class DibiMySqliDriver extends DibiDriver {
|
||||
$conn = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
|
||||
if (!$conn)
|
||||
return new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error", array(
|
||||
'message' => mysqli_connect_error(),
|
||||
'code' => mysqli_connect_errno(),
|
||||
));
|
||||
|
@@ -43,13 +43,13 @@ class DibiOdbcDriver extends DibiDriver {
|
||||
public static function connect($config)
|
||||
{
|
||||
if (!extension_loaded('odbc'))
|
||||
return new DibiException("PHP extension 'odbc' is not loaded");
|
||||
throw new DibiException("PHP extension 'odbc' is not loaded");
|
||||
|
||||
if (!isset($config['username']))
|
||||
return new DibiException("Username must be specified");
|
||||
throw new DibiException("Username must be specified");
|
||||
|
||||
if (!isset($config['password']))
|
||||
return new DibiException("Password must be specified");
|
||||
throw new DibiException("Password must be specified");
|
||||
|
||||
if (empty($config['persistent']))
|
||||
$conn = @odbc_connect($config['database'], $config['username'], $config['password']);
|
||||
@@ -57,7 +57,7 @@ class DibiOdbcDriver extends DibiDriver {
|
||||
$conn = @odbc_pconnect($config['database'], $config['username'], $config['password']);
|
||||
|
||||
if (!is_resource($conn))
|
||||
return new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error", array(
|
||||
'message' => odbc_errormsg(),
|
||||
'code' => odbc_error(),
|
||||
));
|
||||
|
@@ -43,10 +43,10 @@ class DibiPostgreDriver extends DibiDriver {
|
||||
public static function connect($config)
|
||||
{
|
||||
if (!extension_loaded('pgsql'))
|
||||
return new DibiException("PHP extension 'pgsql' is not loaded");
|
||||
throw new DibiException("PHP extension 'pgsql' is not loaded");
|
||||
|
||||
if (empty($config['string']))
|
||||
return new DibiException("Connection string must be specified");
|
||||
throw new DibiException("Connection string must be specified");
|
||||
|
||||
if (empty($config['type'])) $config['type'] = NULL;
|
||||
|
||||
@@ -57,7 +57,7 @@ class DibiPostgreDriver extends DibiDriver {
|
||||
$conn = @pg_pconnect($config['string'], $config['type']);
|
||||
|
||||
if (!is_resource($conn))
|
||||
return new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error", array(
|
||||
'message' => pg_last_error(),
|
||||
));
|
||||
|
||||
|
@@ -44,10 +44,10 @@ class DibiSqliteDriver extends DibiDriver {
|
||||
public static function connect($config)
|
||||
{
|
||||
if (!extension_loaded('sqlite'))
|
||||
return new DibiException("PHP extension 'sqlite' is not loaded");
|
||||
throw new DibiException("PHP extension 'sqlite' is not loaded");
|
||||
|
||||
if (empty($config['database']))
|
||||
return new DibiException("Database must be specified");
|
||||
throw new DibiException("Database must be specified");
|
||||
|
||||
if (!isset($config['mode']))
|
||||
$config['mode'] = 0666;
|
||||
@@ -59,7 +59,7 @@ class DibiSqliteDriver extends DibiDriver {
|
||||
$conn = @sqlite_popen($config['database'], $config['mode'], $errorMsg);
|
||||
|
||||
if (!$conn)
|
||||
return new DibiException("Connecting error", array(
|
||||
throw new DibiException("Connecting error", array(
|
||||
'message' => $errorMsg,
|
||||
));
|
||||
|
||||
@@ -136,7 +136,7 @@ class DibiSqliteDriver extends DibiDriver {
|
||||
|
||||
public function quoteName($value)
|
||||
{
|
||||
return $value;
|
||||
return '[' . $value . ']';
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user