diff options
author | Filipp Lepalaan <filipp@mac.com> | 2010-07-15 23:51:05 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2010-07-15 23:51:05 +0300 |
commit | ad4a149c32bd42bf374b56c88cdf43b5ee801874 (patch) | |
tree | 98dfdd80228531b9c25b23a57607954f0aa715d1 /MainDb.php | |
parent | b4cd2ad59440171ea330ddaad28b4743d4936b51 (diff) | |
download | main-ad4a149c32bd42bf374b56c88cdf43b5ee801874.tar.gz main-ad4a149c32bd42bf374b56c88cdf43b5ee801874.tar.bz2 main-ad4a149c32bd42bf374b56c88cdf43b5ee801874.zip |
sqlite support
Diffstat (limited to 'MainDb.php')
-rw-r--r-- | MainDb.php | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -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(); } |