Detailed PHP Package DB Class Connection Sqlite3

Source: Internet
Author: User
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

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.