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
13 require_once 'lib/WikiDB/backend/PearDB.php';
15 //TODO: create tables on virgin wiki
17 $db = &new DB_sqlite();
18 $db->connect($DBParams['dsn'], array('persistent'=> true) );
19 $result = $db->query("CREATE TABLE $table (comment varchar(50),
20 datetime varchar(50));");
23 class WikiDB_backend_PearDB_sqlite
24 extends WikiDB_backend_PearDB
36 function _lock_tables($write_lock = true) {
37 // NOP - SQLite does all locking automatically
43 function _unlock_tables() {
50 function _serialize($data) {
53 assert(is_array($data));
54 return base64_encode(serialize($data));
60 function _unserialize($data) {
63 // Base64 encoded data does not contain colons.
64 // (only alphanumerics and '+' and '/'.)
65 if (substr($data,0,2) == 'a:')
66 return unserialize($data);
67 return unserialize(base64_decode($data));
70 // same as DB::getSpecialQuery('tables')
72 function sqlite_list_tables (&$dblink) {
74 $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')";
75 if ($res = sqlite_query ($dblink, $sql)) {
76 while (sqlite_has_more($res)) {
77 $tables[] = sqlite_fetch_single($res);
84 function _table_exists (&$dblink, $table) {
85 $sql = "SELECT count(name) FROM sqlite_master WHERE ((type = 'table') and (name = '$table'))";
86 if ($res = sqlite_query ($dblink, $sql)) {
87 return sqlite_fetch_single($res) > 0;
89 return false; // or throw exception
99 // c-hanging-comment-ender-p: nil
100 // indent-tabs-mode: nil