Php to operate sqlite class. Add, delete, modify, query, and pdo links

Source: Internet
Author: User
Php to operate sqlite class. Add, delete, modify, query, and pdo links

Direct code:

Note: You must write the database storage path.

 Db = new PDO ('sqlite :'. dirname (_ FILE __). '\ log. db'); $ this-> table_name = $ tab; $ this-> tab_init ();} public function tab_init () {# table initialization, CREATE a TABLE $ this-> db-> exec ("create table log (id integer primary key autoincrement, urls varchar (200), ip varchar (200 ), datetimes datetime default (datetime ('Now ', 'localtime') ");} public function insert ($ tab_name, $ key_list, $ value_list) {// echo "insert ". $ tab_name. "(". $ key_list. ") Values (". $ value_list. ")"; $ result = $ this-> db-> exec ("insert ". $ tab_name. "(". $ key_list. ") values (". $ value_list. ")"); if (! $ Result) {return false;} // echo "{insert ". $ tab_name. "(". $ key_list. ") values (". $ value_list. ") }}}"; $ res = $ this-> db-> beginTransaction (); // transaction back gun} public function total ($ tab_name, $ tj = '') // calculates the total number of records {$ th = $ this-> db-> prepare ('SELECT count (id) as c from '. $ tab_name. ''. $ tj); $……-> execute (); $ result = $……-> fetchAll (); return $ result [0] ['c'];} public function update () {# modify} function delete ($ value = '') {# delete Except for} public function query ($ tab_name, $ tj = '') // table name and condition {$ Something = $ this-> db-> prepare ('select * from '. $ tab_name. ''. $ tj); // echo 'select * from '. $ tab_name. ''. $ tj; $……-> execute (); $ result = $……-> fetchAll (); return $ result ;}// $ db = new SqliteDB (); // $ res = $ db-> insert ('log', 'Ip, urls, datetimes ',' "127.0.0.1", "www.baidu.com", "00:00:00 "'); // Add case // $ res = $ db-> query ('log'); // query case // $ res = $ db-> total ('log '); // Query the case // print_r ($ res); // foreach ($ res as $ key => $ row) {// echo $ row ['urls']; //}?>

Modify and find yourself .! Call qq 1186969412 if you do not understand

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.