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;
}
}
?>