3 * SQLite PearDB backend by Matthew Palmer
4 * The SQLite DB will gain popularity with the current MySQL vs PHP license drama.
5 * It's in core since PHP-5.0, MySQL not anymore.
8 * sqlite -init /tmp/phpwiki-sqlite.db
9 * sqlite /tmp/phpwiki-sqlite.db < schemas/sqlite.sql
12 require_once 'lib/WikiDB/backend/PearDB.php';
14 //TODO: create tables on virgin wiki
16 $db = &new DB_sqlite();
17 $db->connect($DBParams['dsn'], array('persistent'=> true) );
18 $result = $db->query("CREATE TABLE $table (comment varchar(50),
19 datetime varchar(50));");
22 class WikiDB_backend_PearDB_sqlite
23 extends WikiDB_backend_PearDB
36 function _lock_tables($write_lock = true)
38 // NOP - SQLite does all locking automatically
44 function _unlock_tables()
52 function _serialize($data)
56 assert(is_array($data));
57 return base64_encode(serialize($data));
63 function _unserialize($data)
67 // Base64 encoded data does not contain colons.
68 // (only alphanumerics and '+' and '/'.)
69 if (substr($data, 0, 2) == 'a:')
70 return unserialize($data);
71 return unserialize(base64_decode($data));
74 // same as DB::getSpecialQuery('tables')
76 function sqlite_list_tables (&$dblink) {
78 $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')";
79 if ($res = sqlite_query ($dblink, $sql)) {
80 while (sqlite_has_more($res)) {
81 $tables[] = sqlite_fetch_single($res);
88 function _table_exists(&$dblink, $table)
90 $sql = "SELECT count(name) FROM sqlite_master WHERE ((type = 'table') and (name = '$table'))";
91 if ($res = sqlite_query($dblink, $sql)) {
92 return sqlite_fetch_single($res) > 0;
94 return false; // or throw exception
106 // c-hanging-comment-ender-p: nil
107 // indent-tabs-mode: nil