aboutsummaryrefslogtreecommitdiffstats
path: root/MainDb.php
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2010-07-15 23:51:05 +0300
committerFilipp Lepalaan <filipp@mac.com>2010-07-15 23:51:05 +0300
commitad4a149c32bd42bf374b56c88cdf43b5ee801874 (patch)
tree98dfdd80228531b9c25b23a57607954f0aa715d1 /MainDb.php
parentb4cd2ad59440171ea330ddaad28b4743d4936b51 (diff)
downloadmain-ad4a149c32bd42bf374b56c88cdf43b5ee801874.tar.gz
main-ad4a149c32bd42bf374b56c88cdf43b5ee801874.tar.bz2
main-ad4a149c32bd42bf374b56c88cdf43b5ee801874.zip
sqlite support
Diffstat (limited to 'MainDb.php')
-rw-r--r--MainDb.php33
1 files changed, 26 insertions, 7 deletions
diff --git a/MainDb.php b/MainDb.php
index e672651..6417c19 100644
--- a/MainDb.php
+++ b/MainDb.php
@@ -21,13 +21,20 @@ class MainDb
if (!self::$instance)
{
try {
- self::$instance = new PDO(
- "{$c['db.driver']}:host={$c['db.host']};dbname={$c['db.name']}",
- $c['db.username'], $c['db.password'], array(PDO::ATTR_PERSISTENT => true)
- );
-
- // always use UTF-8?
- self::$instance->query('SET NAMES utf8');
+ switch ($c['db.driver']) {
+ case 'mysql':
+ self::$instance = new PDO(
+ "{$c['db.driver']}:host={$c['db.host']};dbname={$c['db.name']}",
+ $c['db.username'], $c['db.password'], array(PDO::ATTR_PERSISTENT => true)
+ );
+ // always use UTF-8?
+ self::$instance->query('SET NAMES utf8');
+ break;
+
+ case 'sqlite':
+ self::$instance = new PDO('sqlite:'.$c['db.path']);
+ break;
+ }
} catch (PDOException $e) {
exit(MainApp::error($e->getMessage()));
@@ -64,6 +71,13 @@ class MainDb
$pdo = self::getInstance();
$stmt = $pdo->prepare($sql);
+
+ if (!$stmt) {
+ list($ec, $dec, $emsg) = $pdo->errorInfo();
+ $error = $emsg ."\n" . print_r(debug_backtrace(), true);
+ return MainApp::error($error);
+ }
+
$result = $stmt->execute($data);
if (!$result) {
@@ -88,6 +102,11 @@ class MainDb
return $stmt;
}
+ // describe statements need the query results
+ if (preg_match('/^PRAGMA/i', $sql)) {
+ return $stmt;
+ }
+
if (empty($data[':id'])) {
$data[':id'] = $pdo->lastInsertId();
}