Php encapsulates the Method Instance for connecting the db class to the sqlite3 database, dbsqlite3
Preface
The SQLite3 extension is enabled by default in PHP 5.3.0 and later versions. You can use the -- without-sqlite3 to disable it during compilation.
Windows users can use this extension by enabling php_sqlite3.dll. Php_sqlite3.dll is included in the PHP release after PHP 5.3.0 by default.
For detailed installation instructions, refer to the PHP tutorial and its official website.
This article mainly introduces the php encapsulated db class connection sqlite3 and shares it for your reference. I will not talk much about it below. Let's take a look at the details.
Sample Code:
<? Php class dbManager {public $ db; function _ construct () {if (! File_exists ('. /db. php ') {$ this-> init (); return;} $ this-> db = new SQLite3 ('. /db. php ');} function init () {$ this-> db = new SQLite3 ('. /db. php '); // TODO:} function changes () {return $ this-> db-> changes ();} function query ($ SQL, $ param = null, $ memb = null) {$ stmt = $ this-> db-> prepare ($ SQL); if (! $ Stmt) return false; if ($ param) {if (is_array ($ param) {for ($ I = 0; $ I <count ($ param ); $ I ++) $ stmt-> bindValue ($ I + 1, $ param [$ I]);} else {$ stmt-> bindValue (1, $ param) ;}}$ rs = $ stmt-> execute (); if (! $ Rs) {$ stmt-> close (); return false ;}$ arr = $ rs-> fetchArray (SQLITE3_NUM); $ rs-> finalize (); $ stmt-> close (); if (! $ Arr) return null; if (! $ Memb) return $ arr; $ res = array (); for ($ I = 0; $ I <count ($ memb); $ I ++) {$ res [$ memb [$ I] = $ arr [$ I];} return $ res;} function queryAll ($ SQL, $ param = null, $ memb = null) {$ stmt = $ this-> db-> prepare ($ SQL); if (! $ Stmt) return false; if ($ param) {if (is_array ($ param) {for ($ I = 0; $ I <count ($ param ); $ I ++) $ stmt-> bindValue ($ I + 1, $ param [$ I]);} else {$ stmt-> bindValue (1, $ param) ;}}$ rs = $ stmt-> execute (); if (! $ Rs) {$ stmt-> close (); return false;} $ res = array (); while ($ arr = $ rs-> fetchArray (SQLITE3_NUM )) {if (! $ Memb) {$ res [] = $ arr; continue;} if (count ($ memb) = 1 & $ memb [0] = null) {$ res [] = $ arr [0]; continue;} $ it = array (); for ($ I = 0; $ I <count ($ memb ); $ I ++) {$ it [$ memb [$ I] = $ arr [$ I] ;}$ res [] = $ it ;} $ rs-> finalize (); $ stmt-> close (); return $ res;} function querySingle ($ SQL, $ param = null) {$ res = $ this-> query ($ SQL, $ param); if (! $ Res) return false; return $ res [0];} function querySingleAll ($ SQL, $ param = null) {$ stmt = $ this-> db-> prepare ($ SQL); if (! $ Stmt) return false; if ($ param) {if (is_array ($ param) {for ($ I = 0; $ I <count ($ param ); $ I ++) $ stmt-> bindValue ($ I + 1, $ param [$ I]);} else {$ stmt-> bindValue (1, $ param) ;}}$ rs = $ stmt-> execute (); if (! $ Rs) {$ stmt-> close (); return false;} $ res = array (); while ($ arr = $ rs-> fetchArray (SQLITE3_NUM )) {$ res [] = $ arr [0] ;}$ rs-> finalize (); $ stmt-> close (); return $ res;} function exec ($ SQL, $ param = null) {$ stmt = $ this-> db-> prepare ($ SQL); if (! $ Stmt) return false; if ($ param) {if (is_array ($ param) {for ($ I = 0; $ I <count ($ param ); $ I ++) $ stmt-> bindValue ($ I + 1, $ param [$ I]);} else {$ stmt-> bindValue (1, $ param) ;}$ rs = $ stmt-> execute (); if ($ rs) {$ res = true; $ rs-> finalize ();} else {$ res = false;} $ stmt-> close (); return $ res;} function begin () {return $ this-> exec ('begin ');} function rollback () {return $ this-> exec ('rollback');} function commit () {retur N $ this-> exec ('commit ');} function escapeString ($ s) {return $ this-> db-> escapeString ($ s );} // The newly inserted id function lastInsertRowID () {return $ this-> db-> lastInsertRowID ();} function lastErrorMsg () {return $ this-> db-> lastErrorMsg () ;}}?>
PDO supports database migration. If you deploy multiple databases in the future, use it. at the same time, PDO is designed for C and has a high execution efficiency. it has been encapsulated as an extension library component of PHP. fast operation and High Efficiency