PHP operates the SQLite class. Delete and change, PDO link

Source: Internet
Author: User
Tags sqlite

<p> Direct Code:</p><p> Note: Be sure to write a database save path </p>
<?php//SQLite Page class Sqlitedb{public function __construct () {//Initialize database, and connect database Database configuration $this->db = new PDO (' SQLite: '. DirName (__file__). ' \log.db '); $this->table_name= $tab; $this->tab_init ();} Public Function Tab_init () {# table initialization, creating table $this->db->exec ("CREATE table log (ID integer PRIMARY KEY autoincrement,urls varchar ($), IP varchar ($), DateTimes datetime Default (DateTime (' Now ', ' localtime ')));} Public Function Insert ($tab _name, $key _list, $value _list) {//echo ' insert INTO ' $tab _name. " (". $key _list.") VALUES (". $value _list."); $result = $this->db->exec ("INSERT into". $tab _name. " (". $key _list.") VALUES (". $value _list.)"); if (! $result) {return false;} echo "{{{INSERT into". $tab _name. " (". $key _list.") VALUES (". $value _list.")}}} "; $res = $this->db->begintransaction ()//Transaction back Gun}public function Total ($tab _name, $TJ = ")//Sum of records {$sth = $this-  >db->prepare (' SELECT count (ID) as C from '. $tab _name. ' '. $tj); $sth->execute (); $result = $sth->fetchall (); return $result [0][' C '];} Public Function Update () {# modify}function Delete ($value = ') {# delete}public function query ($tab _name, $TJ = ")///table name and condition {$sth = $  This->db->prepare (' SELECT * from '. $tab _name. '  '. $tj);//Echo ' SELECT * from '. $tab _name. ' '. $tj; $sth->execute (); $result = $sth->fetchall (); return $result;}} $db =new Sqlitedb ()//$res = $db->insert (' Log ', ' ip,urls,datetimes ', ' "127.0.0.1", "www.baidu.com", "2012-12-12 00:00:00 "');//Add case//$res = $db->query (' log '),//Query case//$res = $db->total (' log '),//Query Case//Print_r ($res);// foreach ($res as $key = + $row) {//Echo $row [' URLs '];//}?>

Modify and find yourself perfect.! If there is no understanding, call QQ 1186969412


PHP operates the SQLite class. Delete and change, PDO link

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.