Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '3.1/release/3.1.3' into 3.1/master

  • Loading branch information...
commit 0ba6065f6051ca05e937d05cb56a9f1b9401df2e 2 parents 82a47ba + 82709bc
Jeremy Bush zombor authored
8 classes/kohana/database.php
View
@@ -158,12 +158,18 @@ protected function __construct($name, array $config)
/**
* Disconnect from the database. This is called automatically by [Database::__destruct].
+ * Clears the database instance from [Database::$instances].
*
* $db->disconnect();
*
* @return boolean
*/
- abstract public function disconnect();
+ public function disconnect()
+ {
+ unset(Database::$instances[$this->_instance]);
+
+ return TRUE;
+ }
/**
* Set the connection character set. This is called automatically by [Database::connect].
34 classes/kohana/database/exception.php
View
@@ -8,36 +8,4 @@
* @copyright (c) 2009 Kohana Team
* @license http://kohanaphp.com/license
*/
-class Kohana_Database_Exception extends Kohana_Exception {
-
- protected $db_code = NULL;
-
- /**
- * Creates a new translated database exception.
- *
- * throw new Database_Exception(1234, 'Something went terrible wrong, :user',
- * array(':user' => $user));
- *
- * @param string raw DB error code
- * @param string error message
- * @param array translation variables
- * @param integer the exception code
- * @return void
- */
- public function __construct($db_code, $message, array $variables = NULL, $code = 0)
- {
- $this->db_code = $db_code;
-
- parent::__construct($message, $variables, $code);
- }
-
- /**
- * Gets the DB error code
- *
- * @return string
- */
- public function db_code()
- {
- return $this->db_code;
- }
-}
+class Kohana_Database_Exception extends Kohana_Exception {}
44 classes/kohana/database/mysql.php
View
@@ -64,10 +64,9 @@ public function connect()
// No connection exists
$this->_connection = NULL;
- throw new Database_Exception(mysql_errno(), '[:code] :error', array(
- ':code' => mysql_errno(),
- ':error' => mysql_error(),
- ));
+ throw new Database_Exception(':error',
+ array(':error' => mysql_error()),
+ mysql_errno());
}
// \xFF is a better delimiter, but the PHP driver uses underscore
@@ -93,10 +92,9 @@ protected function _select_db($database)
if ( ! mysql_select_db($database, $this->_connection))
{
// Unable to select database
- throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
- ':code' => mysql_errno($this->_connection),
- ':error' => mysql_error($this->_connection),
- ));
+ throw new Database_Exception(':error',
+ array(':error' => mysql_error($this->_connection)),
+ mysql_errno($this->_connection));
}
Database_MySQL::$_current_databases[$this->_connection_id] = $database;
@@ -115,6 +113,9 @@ public function disconnect()
{
// Clear the connection
$this->_connection = NULL;
+
+ // Clear the instance
+ parent::disconnect();
}
}
}
@@ -145,10 +146,9 @@ public function set_charset($charset)
if ($status === FALSE)
{
- throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
- ':code' => mysql_errno($this->_connection),
- ':error' => mysql_error($this->_connection),
- ));
+ throw new Database_Exception(':error',
+ array(':error' => mysql_error($this->_connection)),
+ mysql_errno($this->_connection));
}
}
@@ -178,11 +178,9 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
Profiler::delete($benchmark);
}
- throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error ( :query )', array(
- ':code' => mysql_errno($this->_connection),
- ':error' => mysql_error($this->_connection),
- ':query' => $sql,
- ));
+ throw new Database_Exception(':error [ :query ]',
+ array(':error' => mysql_error($this->_connection), ':query' => $sql),
+ mysql_errno($this->_connection));
}
if (isset($benchmark))
@@ -275,8 +273,9 @@ public function begin($mode = NULL)
if ($mode AND ! mysql_query("SET TRANSACTION ISOLATION LEVEL $mode", $this->_connection))
{
- throw new Database_Exception(mysql_errno($this->_connection), ':error', array(':error' => mysql_error($this->_connection)),
- mysql_errno($this->_connection));
+ throw new Database_Exception(':error',
+ array(':error' => mysql_error($this->_connection)),
+ mysql_errno($this->_connection));
}
return (bool) mysql_query('START TRANSACTION', $this->_connection);
@@ -421,10 +420,9 @@ public function escape($value)
if (($value = mysql_real_escape_string( (string) $value, $this->_connection)) === FALSE)
{
- throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error', array(
- ':code' => mysql_errno($this->_connection),
- ':error' => mysql_error($this->_connection),
- ));
+ throw new Database_Exception(':error',
+ array(':error' => mysql_error($this->_connection)),
+ mysql_errno($this->_connection));
}
// SQL standard is to use single-quotes for all values
20 classes/kohana/database/pdo.php
View
@@ -56,10 +56,9 @@ public function connect()
}
catch (PDOException $e)
{
- throw new Database_Exception($e->getCode(), '[:code] :error', array(
- ':code' => $e->getMessage(),
- ':error' => $e->getCode(),
- ), $e->getCode());
+ throw new Database_Exception(':error',
+ array(':error' => $e->getMessage()),
+ $e->getCode());
}
if ( ! empty($this->_config['charset']))
@@ -74,7 +73,7 @@ public function disconnect()
// Destroy the PDO object
$this->_connection = NULL;
- return TRUE;
+ return parent::disconnect();
}
public function set_charset($charset)
@@ -110,11 +109,12 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
}
// Convert the exception in a database exception
- throw new Database_Exception($e->getCode(), '[:code] :error ( :query )', array(
- ':code' => $e->getMessage(),
- ':error' => $e->getCode(),
- ':query' => $sql,
- ), $e->getCode());
+ throw new Database_Exception(':error [ :query ]',
+ array(
+ ':error' => $e->getMessage(),
+ ':query' => $sql
+ ),
+ $e->getCode());
}
if (isset($benchmark))
Please sign in to comment.
Something went wrong with that request. Please try again.