1
0
mirror of https://github.com/dg/dibi.git synced 2025-10-21 01:36:26 +02:00

refactoring in drivers

This commit is contained in:
David Grudl
2008-09-04 18:18:58 +00:00
parent 52d2ecf5b0
commit f935968aa7
5 changed files with 43 additions and 83 deletions

View File

@@ -126,16 +126,24 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
// affects the character set used by mysql_real_escape_string() (was added in MySQL 5.0.7 and PHP 5.2.3)
$ok = @mysql_set_charset($config['charset'], $this->connection); // intentionally @
}
if (!$ok) $ok = @mysql_query("SET NAMES '$config[charset]'", $this->connection); // intentionally @
if (!$ok) $this->throwException();
if (!$ok) {
$ok = @mysql_query("SET NAMES '$config[charset]'", $this->connection); // intentionally @
if (!$ok) {
throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
}
}
}
if (isset($config['database'])) {
@mysql_select_db($config['database'], $this->connection) or $this->throwException(); // intentionally @
if (!@mysql_select_db($config['database'], $this->connection)) { // intentionally @
throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
}
}
if (isset($config['sqlmode'])) {
if (!@mysql_query("SET sql_mode='$config[sqlmode]'", $this->connection)) $this->throwException(); // intentionally @
if (!@mysql_query("SET sql_mode='$config[sqlmode]'", $this->connection)) { // intentionally @
throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
}
}
$this->buffered = empty($config['unbuffered']);
@@ -171,7 +179,7 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
}
if (mysql_errno($this->connection)) {
$this->throwException($sql);
throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection), $sql);
}
return is_resource($this->resultSet) ? clone $this : NULL;
@@ -385,18 +393,6 @@ class DibiMySqlDriver extends /*Nette::*/Object implements IDibiDriver
/**
* Converts database error to DibiDriverException.
*
* @throws DibiDriverException
*/
protected function throwException($sql = NULL)
{
throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection), $sql);
}
/**
* Returns the connection resource.
*