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
35 function _lock_tables($write_lock = true) {
36 // NOP - SQLite does all locking automatically
42 function _unlock_tables() {
49 function _serialize($data) {
52 assert(is_array($data));
53 return base64_encode(serialize($data));
59 function _unserialize($data) {
62 // Base64 encoded data does not contain colons.
63 // (only alphanumerics and '+' and '/'.)
64 if (substr($data,0,2) == 'a:')
65 return unserialize($data);
66 return unserialize(base64_decode($data));
69 // same as DB::getSpecialQuery('tables')
71 function sqlite_list_tables (&$dblink) {
73 $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')";
74 if ($res = sqlite_query ($dblink, $sql)) {
75 while (sqlite_has_more($res)) {
76 $tables[] = sqlite_fetch_single($res);
83 function _table_exists (&$dblink, $table) {
84 $sql = "SELECT count(name) FROM sqlite_master WHERE ((type = 'table') and (name = '$table'))";
85 if ($res = sqlite_query ($dblink, $sql)) {
86 return sqlite_fetch_single($res) > 0;
88 return false; // or throw exception
98 // c-hanging-comment-ender-p: nil
99 // indent-tabs-mode: nil