diff options
author | Filipp Lepalaan <filipp@mac.com> | 2010-07-20 07:22:23 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2010-07-20 07:22:23 +0300 |
commit | dead03e955367d4635764251f62256365c01b221 (patch) | |
tree | 24696b6896871521b12e36d778f2219f9987ac28 /MainDb.php | |
parent | ad4a149c32bd42bf374b56c88cdf43b5ee801874 (diff) | |
download | main-dead03e955367d4635764251f62256365c01b221.tar.gz main-dead03e955367d4635764251f62256365c01b221.tar.bz2 main-dead03e955367d4635764251f62256365c01b221.zip |
ordering children, PHP 5.3 changes
Diffstat (limited to 'MainDb.php')
-rw-r--r-- | MainDb.php | 40 |
1 files changed, 28 insertions, 12 deletions
@@ -30,7 +30,6 @@ class MainDb // always use UTF-8? self::$instance->query('SET NAMES utf8'); break; - case 'sqlite': self::$instance = new PDO('sqlite:'.$c['db.path']); break; @@ -56,15 +55,27 @@ class MainDb //// // execute an SQL query // @return mixed - public static function query($sql, $data = null) + public static function query($sql, $data = NULL) { - if (!$data) { - $data = array(); + $args = func_get_args(); + $sql = array_shift($args); + + if (!is_string($sql)) { + return false; } - // might be just a string if (!is_array($data)) { + $data = $args; + } + + // might just be a string + if (!is_array($data)) { $data = array($data); + } + + // might be just an empty array + if (empty($data)) { + $data = array(); } try { @@ -74,7 +85,7 @@ class MainDb if (!$stmt) { list($ec, $dec, $emsg) = $pdo->errorInfo(); - $error = $emsg ."\n" . print_r(debug_backtrace(), true); + $error = $emsg ."\n" . print_r(debug_backtrace(), TRUE); return MainApp::error($error); } @@ -82,13 +93,13 @@ class MainDb if (!$result) { list($ec, $dec, $emsg) = $pdo->errorInfo(); - $error = $emsg ."\n" . print_r(debug_backtrace(), true); + $error = $emsg ."\n" . print_r(debug_backtrace(), TRUE); return MainApp::error($error); } } catch (PDOException $e) { $error = $e->getMessage() . $sql; - $error .= "\n" . print_r(debug_backtrace(), true); + $error .= "\n" . print_r(debug_backtrace(), TRUE); return MainApp::error($error); } @@ -102,7 +113,7 @@ class MainDb return $stmt; } - // describe statements need the query results + // pragma statements need the query results (SQLite) if (preg_match('/^PRAGMA/i', $sql)) { return $stmt; } @@ -125,10 +136,15 @@ class MainDb //// // fetch something from DB - public static function fetch($sql, $data = null) + public static function fetch($sql, $data = NULL) { - $stmt = self::query($sql, $data) - or exit(MainApp::error('Error executing query '.$sql)); + $args = func_get_args(); + $sql = array_shift($args); + + if (is_array($data)) { + $args = $data; + } + $stmt = self::query($sql, $args) or exit(MainApp::error('Error executing query '.$sql)); return $stmt->fetchAll(PDO::FETCH_ASSOC); } |