This article mainly introduces the simple operation of the PHP implementation of the SQLite database class and usage, combined with specific examples of the PHP package for SQLite database related additions and deletions to change the operation skills and use of methods, the need for friends can refer to the next
This article describes the simple operation of PHP implementation of the SQLite database class and usage. Share to everyone for your reference, as follows:
SQLite is a lightweight database, is to comply with acid-related database management system, it is designed to be embedded, and has been used in many embedded products, it occupies very low resources, in embedded devices, may only need hundreds of K of memory is enough. It can support Windows/linux/unix and so on mainstream operating system, and can be combined with many programming languages, such as Tcl, PHP, Java, and ODBC interface, also compared to MySQL, PostgreSQL, the two open source world-renowned database management system, is processing faster than they do.
Here is a concise PHP operation for everyone to work with the SQLite class:
<?php/***//Application Example require_once (' cls_sqlite.php ');//Create Instance $db=new sqlite (' blog.db '); This database file names any//CREATE database tables. $DB->query ("CREATE TABLE test (ID integer primary key,title varchar (50))");//Next Add Data $db->query ("INSERT INTO Test ( VALUES (' kimchi ') "), $DB->query (" INSERT INTO Test (' Blue Rain ') "), $DB->query (" INSERT into Test (title) VALUES (' Ajan ')), $DB->query ("INSERT INTO Test (' the") VALUES (' Proud snow Blue Sky ') "),//Read Data Print_r ($DB->getlist (' SELECT * From test ORDER by id DESC ');//Update Data $db->query (' update test set title = "three" where id = 9 '); ***/class sqlite{function Construct ($file) {try {$this->connection=new PDO (' SQLite: ' $file); } catch (Pdoexception $e) {try {$this->connection=new PDO (' Sqlite2: '. $file); } catch (Pdoexception $e) {exit (' error! '); }}} function destruct () {$this->connection=null;} function query ($sql)//Run SQL directly, can be used to update, delete data {return $this->c Onnection->query ($sql); } function GetList ($sql)//Get record list {$recordlist =array (); foreach ($this->query ($sql) as $rstmp) {$recordlist []= $rstmp; } return $recordlist; } function Execute ($sql) {return $this->query ($sql)->fetch ()} function Recordarray ($sql) {return $this->que Ry ($sql)->fetchall (); } function RecordCount ($sql) {return count ($this->recordarray ($sql))} function Recordlastid () {return $this->c Onnection->lastinsertid (); }}?>
Related PHP configuration instructions:
1. First Test whether PHP can connect to the SQLite database:
Create a PHP file
<?php$conn = Sqlite_open (' test.db ');? >
Test whether the file is functioning properly.
This error can occur if the SQLite module is not loaded properly:
Fatal error:call to undefined function sqlite_open () inch C:\Apache\Apache2\htdocs\test.php on line 2
The solution is as follows:
2. Open the php.ini file and delete the preceding three lines of the semicolon:
; Extension=php_sqlite.dll;extension=php_pdo.dll;extension=php_pdo_sqlite.dll
Restarting the Web server