PHP SQLite class _php Tips

Source: Internet
Author: User
Tags sqlite
Copy Code code as follows:

?
/**
* SQLite class
* 2009-5-6
* Even Wanchun
*
*/
Class SQLite {
Current SQL directive
Public $_mquerystr = ';
Current results
public $_mresult = null;
SQLite connection Handle
protected $_msqlite;
Warning message
protected $_merrorinfo;
/**
* Database Connection Construction Class
*
* @param string $databaseFile database file
* @return Unknown
*/
Public function __construct ($databaseFile) {
if (file_exists ($databaseFile)) {
$this->_msqlite = new PDO (' SQLite: '. $databaseFile);
}else{
$this->_merrorinfo= "database file not found";
return false;
}
}
/**
* The database has a statement operation that returns results
*
* @param srting $sql SQL statements
* @return Unknown
*/
Public Function GetAll ($sql) {
if (empty ($sql)) {
$this->_merrorinfo= "SQL statement error";
return false;
}
$result = $this->_msqlite->prepare ($sql);
if (false = = $result) {
return Array ();
}
$result->execute ();
$this->_mresult = $result->fetchall ();
if (false = = $this->_mresult) {
return Array ();
}
return $this->_mresult;
}
/**
* Perform insert,delete,updata operation
*
* @param srting $sql SQL statements
* @return Unknown
*/
Public Function Query ($sql) {
if (empty ($sql)) {
$this->_merrorinfo= "SQL statement error";
return false;
}
$this->_msqlite->exec ($sql) or Die (Print_r ($this->_msqlite->errorinfo ()));
$this->_msqlite->exec ($sql);
return true;
}
/**
* Return error message
*
* @return Unknown
*/
Public Function SetError () {
return $this->_merrorinfo;
}
}
?>
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.