Database connection tweaks

This commit is contained in:
Timothy Warren 2012-05-02 12:53:34 -04:00
parent 31ba0881ea
commit dcdf581998
3 changed files with 12 additions and 15 deletions

View File

@ -158,21 +158,17 @@ class Query_Builder {
// Convert array to object // Convert array to object
if (is_array($params)) if (is_array($params))
{ {
$p = new StdClass(); $p = new ArrayObject($params);
foreach($params as $key => $val)
{
$p->$key = $val;
}
$params = $p; $params = $p;
} }
// Let the connection work with 'conn_db' or 'database' // Let the connection work with 'conn_db' or 'database'
$params->conn_db = ( ! isset($params->database)) if (isset($params->database))
? @$params->conn_db {
: @$params->database; $params->conn_db = $params->database;
}
$params->type = strtolower($params->type); $params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql'; $dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
@ -213,6 +209,7 @@ class Query_Builder {
$this->db = new $dbtype($dsn); $this->db = new $dbtype($dsn);
} }
// Set the connection name property, if applicable
if (isset($params->name)) if (isset($params->name))
{ {
$this->conn_name = $params->name; $this->conn_name = $params->name;

View File

@ -25,10 +25,10 @@ class MySQLTest extends DBTest {
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
if (is_file(QBASE_DIR . "test_config.json")) if (is_file(QBASE_DIR . "test_config.json"))
{ {
$params = json_decode(file_get_contents(QBASE_DIR . "test_config.json")); $params = json_decode(file_get_contents(QBASE_DIR . "test_config.json"), TRUE);
$params = $params->mysql; $params = $params['mysql'];
$this->db = new MySQL("host={$params->host};port={$params->port};dbname={$params->database}", $params->user, $params->pass); $this->db = new MySQL("host={$params['host']};port={$params['port']};dbname={$params['database']}", $params['user'], $params['pass']);
} }
elseif (($var = getenv('CI'))) elseif (($var = getenv('CI')))
{ {

Binary file not shown.