Improved Query Builder

This commit is contained in:
Timothy Warren 2012-03-28 20:32:33 -04:00
parent 43e7bfeb39
commit ff3fba3e37

View File

@ -78,27 +78,37 @@ class Query_Builder {
$params->type = strtolower($params->type); $params->type = strtolower($params->type);
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql'; $dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
// Initiate the constructor for the selected database // Create the dsn for the database to connect to
switch($dbtype) switch($dbtype)
{ {
default: default:
$this->db = new $dbtype("host={$params->host};port={$params->port};dbname={$params->database}", $params->user, $params->pass); if ( ! empty($params->port))
break;
case "sqlite":
if ( ! empty($params->user) && ! empty($params->pass))
{ {
$this->db = new $dbtype($params->file, $params->user, $params->pass); $dsn = "host={$params->host};dbname={$params->database}";
} }
else else
{ {
$this->db = new $dbtype($params->file); $dsn = "host={$params->host};port={$params->port};dbname={$params->database}";
} }
break; break;
case "firebird": case "sqlite":
$this->db = new $dbtype("{$params->host}:{$params->file}", $params->user, $params->pass); $dsn = $params->file;
break; break;
case "firebird":
$dsn = "{$params->host}:{$params->file}";
break;
}
// Create the database connection
if ( ! empty($params->user) && ! empty($params->pass))
{
$this->db = new $dbtype($dsn, $params->user, $params->pass);
}
else
{
$this->db = new $dbtype($dsn);
} }
// Make things just slightly shorter // Make things just slightly shorter