mirror of
https://github.com/dg/dibi.git
synced 2025-10-20 01:06:25 +02:00
* better syntax highlighting
* all drivers checks for extension in constructor * DibiMySqlDriver - charset is set by mysql_set_charset * DibiMySqliDriver - charset is set by mysqli_set_charset
This commit is contained in:
@@ -63,6 +63,19 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
|
||||
private $buffered;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (!extension_loaded('mysql')) {
|
||||
throw new DibiDriverException("PHP extension 'mysql' is not loaded");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Connects to a database
|
||||
*
|
||||
@@ -71,10 +84,6 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
|
||||
*/
|
||||
public function connect(array &$config)
|
||||
{
|
||||
if (!extension_loaded('mysql')) {
|
||||
throw new DibiException("PHP extension 'mysql' is not loaded");
|
||||
}
|
||||
|
||||
DibiConnection::alias($config, 'username', 'user');
|
||||
DibiConnection::alias($config, 'password', 'pass');
|
||||
DibiConnection::alias($config, 'options');
|
||||
@@ -110,12 +119,17 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
|
||||
}
|
||||
|
||||
if (isset($config['charset'])) {
|
||||
@mysql_query("SET NAMES '" . $config['charset'] . "'", $this->connection);
|
||||
// don't handle this error...
|
||||
$ok = FALSE;
|
||||
if (function_exists('mysql_set_charset')) {
|
||||
// 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);
|
||||
}
|
||||
if (!$ok) $ok = @mysql_query("SET NAMES '" . $config['charset'] . "'", $this->connection);
|
||||
if (!$ok) $this->throwException();
|
||||
}
|
||||
|
||||
if (isset($config['database']) && !@mysql_select_db($config['database'], $this->connection)) {
|
||||
$this->throwException();
|
||||
if (isset($config['database'])) {
|
||||
@mysql_select_db($config['database'], $this->connection) or $this->throwException();
|
||||
}
|
||||
|
||||
$this->buffered = empty($config['unbuffered']);
|
||||
|
Reference in New Issue
Block a user