PEAR:DB wrapper around SQLite

From: Date: Sun, 25 May 2003 14:55:55 +0000
Subject: PEAR:DB wrapper around SQLite
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16677@lists.php.net to get a copy of this message
dear all i was thinking of writing a db wrapper for sqlite based on pear:db. sqlite is quite different from other databases wrapped in pear as it does not need a host, but calls directly a database file at sqlite_open("./testdb" ), which is show below in a simple script. there is also a way to use sqlite with odbc, also described below. you will need the sqlite odbc driver from christian werner - http://www.ch-werner.de/sqliteodbc/html/ - which works pretty well. so, i just would like to know, if anyone has an idea, how the pear:db dsn could be hacked or configured to take files as arguments; you may also argue, that we do not need such a wrapper ;) on the other hand there is more progress on the sqlite devlopment, as you might have a look at andreis "mod_auth_sqlite": http://www.gravitonic.com/software/other/ thanx, urs -- <?php if (!extension_loaded('sqlite')) { if (!dl(stristr(PHP_OS, "WIN") ? "php_sqlite.dll" : "php_sqlite.so")) { exit("Could not load extension SQLITE.\n"); } } else { echo "Extension loaded.\n"; //print_r(get_extension_funcs("sqlite")); } function odbc_fetch_assoc($res, $affected=1) { $stack = array(); if (odbc_fetch_row($res)) { if($affected) $stack = array("odbc_affected_rows"=>odbc_num_rows($res)); for($i=1; $i<=odbc_num_fields($res); $i++) { $key = odbc_field_name($res, $i); $val = odbc_result($res, $key); $stack = array_merge($stack, array($key => $val)); } return $stack; } else { return false; } } // via ODBC $db = odbc_connect("DSN=SQLite.1;UID=;PWD=", "", "", SQL_CUR_USE_DRIVER); $result = odbc_exec($db, "SELECT * from tbl1;") or die("Error: " . odbc_errormsg()); if (odbc_fetch_row($result)) { for($i=1; $i<=odbc_num_fields($result); $i++) { $key = odbc_field_name($result, $i); $val = odbc_result($result, $key); $stack[$i-1] = array($key => $val); } } print_r($stack); // via PECL SQLite extension $database = "./var/testdb"; $db = sqlite_open($database); $r = sqlite_query("SELECT * from tbl1;", $db); $stack = sqlite_fetch_array($r, SQLITE_NUM); sqlite_close($GLOBALS['db']); print_r($stack); ?>

« previous php.pear.dev (#16677) next »