Simple PHP operation for SQLite class

Source: Internet
Author: User
Tags sqlite sqlite database

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->connection->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->query ($sql)->fetchall ();} function RecordCount ($sql) {return count ($this->recordarray ($sql));} function Recordlastid () {return $this->connection->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

http://blog.csdn.net/diandian_520/article/details/7231855

Simple PHP operation for SQLite class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.