Php-php Tutorial

Source: Internet
Author: User
Php SQLite class code sharing
This article introduces a class used to operate sqlite data in php programming. here we will share the code. if you need it, please refer to it.

Provides a PHP SQLite class:

     Any database file name // create database "title =" database "> database table. $ DB-> query ("create table test (id integer primary key, title varchar (50 ))"); // add the data $ DB-> query ("insert into test (title) values ('hut ')"); $ DB-> query ("insert into test (title) values ('Blue Rain') "); $ DB-> query (" insert into test (title) values ('ajand ')"); $ DB-> query ("insert into test (title) values ('sjolzy ')"); // read data print_r ($ DB-> getlist ('select * from test order by id desc ')); // update data $ DB-> query ('update test set title = "Three major" 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 or delete data return $ this-> connection-> query ($ SQL);} function getlist ($ SQL) {// Retrieve 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)-> fe TchAll ();} function RecordCount ($ SQL) {return count ($ this-> RecordArray ($ SQL);} function RecordLastID () {return $ this-> connection-> lastInsertId () ;}}?>

Appendix, related PHP configuration instructions:

1. first test whether PHP can connect to the sqlite database "title =" database "> Database: Create a PHP file.

     

Whether the test file runs normally.

If the sqlite module fails to be loaded normally, the following error may occur: Fatal error: Call to undefined function sqlite_open () in C: \ Apache \ Apache2 \ htdocs \ test. php on line 2.

Solution: Open the php. ini file, remove the semicolon before the following three lines, that is, remove the comment to make the configuration section take effect:

; Extension = php_sqlite.dll; extension = php_pdo.dll; extension = php_pdo_sqlite.dll

Restart apache or nginx to make the configuration take effect.

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.