More Query Builder additions
This commit is contained in:
parent
8b404a9465
commit
8886218c66
@ -23,13 +23,24 @@ class Query_Builder {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $conn_name - the name of the connection
|
||||
* @param mixed $conn_name - the name of the connection/parameters
|
||||
*/
|
||||
function __construct($conn_name)
|
||||
{
|
||||
|
||||
// Add some flexibility for testing
|
||||
if(class_exists('settings'))
|
||||
{
|
||||
$this->settings =& Settings::get_instance();
|
||||
|
||||
$params = $this->settings->get_db($conn_name);
|
||||
$params = (is_scalar($conn_name))
|
||||
? $this->settings->get_db($conn_name)
|
||||
: $conn_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
$params = $conn_name;
|
||||
}
|
||||
|
||||
$params->type = strtolower($params->type);
|
||||
$dbtype = ($params->type !== 'postgresql') ? $params->type : 'pgsql';
|
||||
@ -42,7 +53,14 @@ class Query_Builder {
|
||||
break;
|
||||
|
||||
case "sqlite":
|
||||
if ( ! empty($params->user) && ! empty($params->pass))
|
||||
{
|
||||
$this->db = new $dbtype($params->file, $params->user, $params->pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db = new $dbtype($params->file);
|
||||
}
|
||||
break;
|
||||
|
||||
case "firebird":
|
||||
@ -53,6 +71,18 @@ class Query_Builder {
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
public function __get($key)
|
||||
{
|
||||
if (isset($this->db->$key))
|
||||
{
|
||||
return $this->db->$key;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shortcut to directly call database methods
|
||||
*
|
||||
@ -62,15 +92,16 @@ class Query_Builder {
|
||||
*/
|
||||
public function __call($name, $params)
|
||||
{
|
||||
if (is_callable($this->$db->$name))
|
||||
if (isset($this->db->$name))
|
||||
{
|
||||
return call_user_func_array(array(&$this->db, $name), $params);
|
||||
if (is_callable($this->db->$name))
|
||||
{
|
||||
return call_user_func_array($this->db->$name, $params);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
@ -32,6 +32,8 @@ function do_include($path)
|
||||
// Include core tests
|
||||
require_once("core.php");
|
||||
require_once("../sys/common/db_pdo.php");
|
||||
require_once("../sys/common/query_builder.php");
|
||||
|
||||
|
||||
// Include db tests
|
||||
// Load db classes based on capability
|
||||
|
Loading…
Reference in New Issue
Block a user