1
0
mirror of https://github.com/dg/dibi.git synced 2025-03-13 19:00:05 +01:00

MySQL & MySQLi drivers: configuration items 'options' renamed to 'flags' (old name is alias); added array 'options' for MySQLi

This commit is contained in:
David Grudl 2010-08-03 19:38:06 +02:00
parent dc3b1ff399
commit 66e709e846
3 changed files with 24 additions and 10 deletions

View File

@ -24,7 +24,7 @@
* - 'database' - the database name to select
* - 'charset' - character encoding to set
* - 'unbuffered' - sends query without fetching and buffering the result rows automatically?
* - 'options' - driver specific constants (MYSQL_*)
* - 'flags' - driver specific constants (MYSQL_CLIENT_*)
* - 'sqlmode' - see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
@ -68,13 +68,12 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiReflector
*/
public function connect(array &$config)
{
$foo = & $config['options'];
if (isset($config['resource'])) {
$this->connection = $config['resource'];
} else {
// default values
DibiConnection::alias($config, 'flags', 'options');
if (!isset($config['username'])) $config['username'] = ini_get('mysql.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('mysql.default_password');
if (!isset($config['host'])) {
@ -95,9 +94,9 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiReflector
}
if (empty($config['persistent'])) {
$this->connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['options']); // intentionally @
$this->connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['flags']); // intentionally @
} else {
$this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['options']); // intentionally @
$this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['flags']); // intentionally @
}
}

View File

@ -24,7 +24,8 @@
* - 'database' - the database name to select
* - 'charset' - character encoding to set
* - 'unbuffered' - sends query without fetching and buffering the result rows automatically?
* - 'options' - driver specific constants (MYSQLI_*)
* - 'flags' - driver specific bit constants (MYSQLI_CLIENT_*) {@see mysqli_real_connect}
* - 'options' - array of driver specific constants (MYSQLI_*) and values {@see mysqli_options}
* - 'sqlmode' - see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
* - 'lazy' - if TRUE, connection will be established only when required
* - 'resource' - connection resource (optional)
@ -68,9 +69,6 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiReflector
*/
public function connect(array &$config)
{
$foo = & $config['options'];
$foo = & $config['database'];
mysqli_report(MYSQLI_REPORT_OFF);
if (isset($config['resource'])) {
$this->connection = $config['resource'];
@ -92,8 +90,21 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiReflector
}
}
$foo = & $config['flags'];
$foo = & $config['database'];
$this->connection = mysqli_init();
@mysqli_real_connect($this->connection, $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['options']); // intentionally @
if (isset($config['options'])) {
if (is_scalar($config['options'])) {
$config['flags'] = $config['options']; // back compatibility
trigger_error(__CLASS__ . ": configuration item 'options' must be array; for constants MYSQLI_CLIENT_* use 'flags'.", E_USER_NOTICE);
} else {
foreach ((array) $config['options'] as $key => $value) {
mysqli_options($this->connection, $key, $value);
}
}
}
@mysqli_real_connect($this->connection, $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['flags']); // intentionally @
if ($errno = mysqli_connect_errno()) {
throw new DibiDriverException(mysqli_connect_error(), $errno);

View File

@ -66,6 +66,10 @@ try {
'password' => 'xxx',
'database' => 'dibi',
'charset' => 'utf8',
'options' => array(
MYSQLI_OPT_CONNECT_TIMEOUT => 30
),
'flags' => MYSQLI_CLIENT_COMPRESS,
));
echo 'OK';