diff --git a/autoload.php b/autoload.php
index 370f1b6..4868aef 100644
--- a/autoload.php
+++ b/autoload.php
@@ -50,10 +50,7 @@ function query_autoload($class)
$driver_path = QDRIVER_PATH . "{$class}";
- if (is_file($class_path))
- {
- require_once($class_path);
- }
+ if (is_file($class_path)) require_once($class_path);
elseif (is_dir($driver_path))
{
if (in_array($class, PDO::getAvailableDrivers()))
diff --git a/classes/db_pdo.php b/classes/db_pdo.php
index 167bd90..e63df7f 100644
--- a/classes/db_pdo.php
+++ b/classes/db_pdo.php
@@ -207,7 +207,7 @@ abstract class DB_PDO extends PDO {
* @return string
*/
public function quote_ident($ident)
- {
+ {
if (is_array($ident))
{
return array_map(array($this, __METHOD__), $ident);
@@ -217,7 +217,7 @@ abstract class DB_PDO extends PDO {
if (strpos($ident, ',') !== FALSE)
{
$parts = explode(',', $ident);
- $parts = array_map('mb_trim', $parts);
+ $parts = array_map('mb_trim', $parts);
$parts = array_map(array($this, __METHOD__), $parts);
$ident = implode(',', $parts);
}
@@ -256,7 +256,7 @@ abstract class DB_PDO extends PDO {
public function _quote($str)
{
// Don't add additional quotes, or quote numbers
- if (strpos($str, $this->escape_char) === 0 ||
+ if (strpos($str, $this->escape_char) === 0 ||
strrpos($str, $this->escape_char) === 0 ||
( ! is_string($str) && is_numeric($str))
)
@@ -412,6 +412,12 @@ abstract class DB_PDO extends PDO {
*/
public function driver_query($sql, $filtered_index=TRUE)
{
+ // Return if the values are returned instead of a query
+ if (is_array($sql))
+ {
+ return $sql;
+ }
+
// Return if the query doesn't apply to the driver
if ($sql === NULL)
{
@@ -442,7 +448,7 @@ abstract class DB_PDO extends PDO {
if (preg_match($regex, $this->last_query, $output) > 0)
{
$stmt = $this->query("SELECT COUNT(*) FROM {$output[1]}");
- return $stmt->fetchColumn();
+ return (int) $stmt->fetchColumn();
}
return NULL;
@@ -459,10 +465,10 @@ abstract class DB_PDO extends PDO {
* @return void
*/
abstract public function truncate($table);
-
+
// --------------------------------------------------------------------------
-
- /**
+
+ /**
* Create sql for batch insert
*
* @param string $table
@@ -472,30 +478,30 @@ abstract class DB_PDO extends PDO {
public function insert_batch($table, $data=array())
{
if ( ! is_array($data[0])) return NULL;
-
+
$table = $this->quote_table($table);
$fields = array_keys($data[0]);
$vals = array();
-
+
$sql = "INSERT INTO {$table} (";
$sql .= implode(',', $this->quote_ident($fields));
$sql .= ") VALUES ";
-
+
$params = array_fill(0, count($fields), '?');
$param_string = implode(',', $params);
-
+
// Remove the first array after use, as it is a special case
$sql .= "({$param_string})";
$vals = array_values($data[0]);
array_shift($data);
-
- // Add another grouping for each
+
+ // Add another grouping for each
foreach($data as $group)
{
$sql .= ",({$param_string})";
$vals = array_merge($vals, array_values($group));
}
-
+
return array($sql, $vals);
}
}
diff --git a/common.php b/common.php
index d2b8a40..3546c94 100644
--- a/common.php
+++ b/common.php
@@ -103,7 +103,7 @@ function db_filter($array, $index)
function Query($params = '')
{
static $connections;
-
+
// If you are getting a previously created connection
if (is_scalar($params))
{
@@ -116,7 +116,7 @@ function Query($params = '')
{
return end($connections);
}
-
+
throw new InvalidArgumentException("The specified connection does not exist");
}
@@ -149,10 +149,10 @@ function Query($params = '')
{
throw new BadDBDriverException('Database driver does not exist, or is not supported');
}
-
+
// Set additional PDO options
$options = array();
-
+
if (isset($params->options))
{
$options = (array)$params->options;
@@ -163,30 +163,24 @@ function Query($params = '')
// --------------------------------------------------------------------------
// Create the dsn for the database to connect to
- switch($dbtype)
+ if ($dbtype === 'firebird') $dsn = "{$params->host}:{$params->file}";
+ elseif ($dbtype === 'sqlite') $dsn = $params->file;
+ else
{
- default:
+ if ( ! empty($params->conn_db))
+ {
$dsn .= "dbname={$params->conn_db}";
+ }
- if ( ! empty($params->host))
- {
- $dsn .= ";host={$params->host}";
- }
+ if ( ! empty($params->host))
+ {
+ $dsn .= ";host={$params->host}";
+ }
- if ( ! empty($params->port))
- {
- $dsn .= ";port={$params->port}";
- }
-
- break;
-
- case "sqlite":
- $dsn .= $params->file;
- break;
-
- case "firebird":
- $dsn = "{$params->host}:{$params->file}";
- break;
+ if ( ! empty($params->port))
+ {
+ $dsn .= ";port={$params->port}";
+ }
}
try
diff --git a/docs/classes/BadConnectionException.html b/docs/classes/BadConnectionException.html
index 3105189..4ec30af 100644
--- a/docs/classes/BadConnectionException.html
+++ b/docs/classes/BadConnectionException.html
@@ -90,7 +90,7 @@
Template is built using Twitter Bootstrap 2 and icons provided by Glyphicons.
Documentation is powered by phpDocumentor 2.2.0
and
- generated on 2014-02-25T13:47:10-05:00.
+ generated on 2014-02-25T13:54:06-05:00.