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