<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