The Sqlite3_open is an API function (c + +) of the SQLite database that opens (or creates) a database file. This article is mainly to share with you the PHP package DB Class Connection Sqlite3 knowledge, hope to help everyone.
<?php class dbmanager{public $db; function __construct () {if (!file_exists ('./db.php ')) {$this->init (); Return } $this->db = new SQLite3 ('./db.php '); } function init () {$this->db = new SQLite3 ('./db.php '); TODO:} function changes () {return $this->db->changes (); } function query ($sql, $param =null, $memb =null) {$stmt = $this->db->prepare ($sql); if (! $stmt) return false; if ($param) {if (Is_array ($param)) {for ($i =0; $i <count ($param); $i + +) $stmt->bindvalue ($i +1, $param [$i]); }else{$stmt->bindvalue (1, $param); }} $rs = $stmt->execute (); if (! $rs) {$stmt->close (); return false; } $arr = $rs->fetcharray (sqlite3_num); $rs->finalize (); $stmt->close (); if (! $arr) return null; if (! $memb) return $arr; $res =array (); for ($i =0; $i <count ($MEMB), $i + +) {$res [$memb [$i]]= $arr [$i]; } return $res; } function Queryall ($sql, $param =null, $memb =null) {$stmt = $this->db->prepare ($sql); if (! $stmt) return false; if ($param) {if (Is_array ($param)) {for ($i =0; $i <count ($param); $i + +) $stmt->bindvalue ($i +1, $param [$i]); }else{$stmt->bindvalue (1, $param); }} $rs = $stmt->execute (); if (! $rs) {$stmt->close (); return false; } $res =array (); while ($arr = $rs->fetcHarray (Sqlite3_num)) {if (! $memb) {$res []= $arr; Continue } if (count ($memb) ==1 && $memb [0]==null) {$res []= $arr [0]; Continue } $it =array (); for ($i =0; $i <count ($MEMB), $i + +) {$it [$memb [$i]]= $arr [$i]; } $res []= $it; } $rs->finalize (); $stmt->close (); return $res; } function Querysingle ($sql, $param =null) {$res = $this->query ($sql, $param); if (! $res) return false; return $res [0]; } function Querysingleall ($sql, $param =null) {$stmt = $this->db->prepare ($sql); if (! $stmt) return false; if ($param) {if (Is_array ($param)) {for ($i =0; $i <count ($param); $i + +) $stmt->bindvalue ($i +1, $param [$i]); }else{$stmt->bindvalue (1, $param); }} $rs = $stmt->execute (); if (! $rs) {$stmt->close (); return false; } $res =array (); while ($arr = $rs->fetcharray (sqlite3_num)) {$res []= $arr [0]; } $rs->finalize (); $stmt->close (); return $res; } function exec ($sql, $param =null) {$stmt = $this->db->prepare ($sql); if (! $stmt) return false; if ($param) {if (Is_array ($param)) {for ($i =0; $i <count ($param); $i + +) $stmt->bindvalue ($i +1, $param [$i]); }else{$stmt->bindvalue (1, $param); }} $rs = $stmt->execute (); if ($rs) {$res =true; $rs->finalize (); }else{$res =false; } $stmt->close (); return $res; } function begin () {return $this->exec (' begin '); } function rollback () {return $this->exec (' rollback '); } function commit () {return $this->exec (' commit '); } function escapestring ($s) {return $this->db->escapestring ($s); }//The newly inserted ID function Lastinsertrowid () {return $this->db->lastinsertrowid (); } function Lasterrormsg () {return $this->db->lasterrormsg (); } }
?>
PDO supports database porting, and if your deployment has multiple databases in the future, use it. At the same time, PDO is a C design with high execution efficiency. He has encapsulated the extension library component for PHP. Fast and efficient operation