Permalink
Browse files

Merge branch '3.1/develop' into 3.2/develop. Refs #3929

  • Loading branch information...
2 parents 82a47ba + c2adc4d commit 65c4c3a654aee2b0e21d30d68e807272f1bb6438 @cbandy cbandy committed Apr 17, 2011
Showing with 35 additions and 32 deletions.
  1. +7 −1 classes/kohana/database.php
  2. +18 −21 classes/kohana/database/mysql.php
  3. +10 −10 classes/kohana/database/pdo.php
View
8 classes/kohana/database.php
@@ -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].
View
39 classes/kohana/database/mysql.php
@@ -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))
@@ -421,10 +419,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
View
20 classes/kohana/database/pdo.php
@@ -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))

0 comments on commit 65c4c3a

Please sign in to comment.