mirror of
https://github.com/dg/dibi.git
synced 2025-08-11 08:34:59 +02:00
* support for default values (mysql.default_user etc...)
This commit is contained in:
@@ -48,12 +48,16 @@ class DibiMySqlDriver extends DibiDriver {
|
||||
if (!extension_loaded('mysql'))
|
||||
throw new DibiException("PHP extension 'mysql' is not loaded");
|
||||
|
||||
foreach (array('username', 'password', 'protocol') as $var)
|
||||
if (!isset($config[$var])) $config[$var] = NULL;
|
||||
// default values
|
||||
if (empty($config['username'])) $config['username'] = ini_get('mysql.default_user');
|
||||
if (empty($config['password'])) $config['password'] = ini_get('mysql.default_password');
|
||||
if (empty($config['host'])) {
|
||||
$config['host'] = ini_get('mysql.default_host');
|
||||
if (empty($config['port'])) ini_get('mysql.default_port');
|
||||
if (empty($config['host'])) $config['host'] = 'localhost';
|
||||
}
|
||||
|
||||
if (empty($config['host'])) $config['host'] = 'localhost';
|
||||
|
||||
if ($config['protocol'] === 'unix') // host can be socket
|
||||
if (isset($config['protocol']) && $config['protocol'] === 'unix') // host can be socket
|
||||
$host = ':' . $config['host'];
|
||||
else
|
||||
$host = $config['host'] . (empty($config['port']) ? '' : ':'.$config['port']);
|
||||
|
@@ -45,10 +45,15 @@ class DibiMySqliDriver extends DibiDriver {
|
||||
if (!extension_loaded('mysqli'))
|
||||
throw new DibiException("PHP extension 'mysqli' is not loaded");
|
||||
|
||||
if (empty($config['host'])) $config['host'] = 'localhost';
|
||||
|
||||
foreach (array('username', 'password', 'database', 'port') as $var)
|
||||
if (!isset($config[$var])) $config[$var] = NULL;
|
||||
// default values
|
||||
if (empty($config['username'])) $config['username'] = ini_get('mysqli.default_user');
|
||||
if (empty($config['password'])) $config['password'] = ini_get('mysqli.default_password');
|
||||
if (empty($config['host'])) {
|
||||
$config['host'] = ini_get('mysqli.default_host');
|
||||
if (empty($config['port'])) ini_get('mysqli.default_port');
|
||||
if (empty($config['host'])) $config['host'] = 'localhost';
|
||||
}
|
||||
if (!isset($config['database'])) $config['database'] = NULL;
|
||||
|
||||
$conn = @mysqli_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
|
||||
|
@@ -44,12 +44,20 @@ class DibiOdbcDriver extends DibiDriver {
|
||||
if (!extension_loaded('odbc'))
|
||||
throw new DibiException("PHP extension 'odbc' is not loaded");
|
||||
|
||||
if (!isset($config['username']))
|
||||
// default values
|
||||
if (empty($config['username'])) $config['username'] = ini_get('odbc.default_user');
|
||||
if (empty($config['password'])) $config['password'] = ini_get('odbc.default_pw');
|
||||
if (empty($config['database'])) $config['database'] = ini_get('odbc.default_db');
|
||||
|
||||
if (empty($config['username']))
|
||||
throw new DibiException("Username must be specified");
|
||||
|
||||
if (!isset($config['password']))
|
||||
if (empty($config['password']))
|
||||
throw new DibiException("Password must be specified");
|
||||
|
||||
if (empty($config['database']))
|
||||
throw new DibiException("Database must be specified");
|
||||
|
||||
if (empty($config['persistent']))
|
||||
$conn = @odbc_connect($config['database'], $config['username'], $config['password']);
|
||||
else
|
||||
|
Reference in New Issue
Block a user