10 * This source file is subject to the new BSD license that is bundled
11 * with this package in the file LICENSE.
12 * It is also available through the world-wide-web at this URL:
13 * http://phergie.org/license
17 * @author Phergie Development Team <team@phergie.org>
18 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
19 * @license http://phergie.org/license New BSD License
20 * @link http://pear.phergie.org/package/Phergie
24 * Provides basic management for SQLite databases
28 * @author Phergie Development Team <team@phergie.org>
29 * @license http://phergie.org/license New BSD License
30 * @link http://pear.phergie.org/package/Phergie
32 class Phergie_Db_Sqlite extends Phergie_Db_Manager
49 * Allows setting of the database file path when creating the class.
51 * @param string $dbFile database file path (optional)
55 public function __construct($dbFile = null)
57 if ($dbFile != null) {
58 $this->setDbFile($dbFile);
63 * Sets the database file path.
65 * @param string $dbFile SQLite database file path
69 public function setDbFile($dbFile)
71 if (is_string($dbFile) && !empty($dbFile)) {
72 $this->dbFile = $dbFile;
77 * Returns a configured database connection.
81 public function getDb()
83 if (!empty($this->db)) {
87 $dir = dirname($this->dbFile);
88 if (!is_dir($dir) && !mkdir($dir, 0755, true)) {
89 throw new Phergie_Db_Exception(
90 'Unable to create directory',
91 Phergie_Db_Exception::ERR_UNABLE_TO_CREATE_DIRECTORY
95 $this->db = new PDO('sqlite:' . $this->dbFile);
102 * Returns whether a given table exists in the database.
104 * @param string $table Name of the table to check for
106 * @return boolean TRUE if the table exists, FALSE otherwise
108 public function hasTable($table)
110 $db = $this->getDb();
112 return (bool) $db->query(
113 'SELECT COUNT(*) FROM sqlite_master WHERE name = '