php存取sqlite資料庫的例子

WBOY
發布: 2016-07-25 08:57:43
原創
1642 人瀏覽過
  1. $dbconn = sqlite_open('phpdb');

  2. if ($dbconn) {

  3. sqlite_query($dbconn, "CREATE TABLE animal(Name VARCHAR(255), MaxAge INT);");
  4. sqlite_query($dbconn, "INSERT INTO animal VALUES ('A', 15)");
  5. $result = sqlite_query($dbconn, "SELECT Name FROM animal");
  6. var_dump(sqlite_fetch_array($result, SQLITE_ASSOC));
  7. } else {
  8. print "Connection to database failed!n";
  9. }

复制代码

例2,将结果集保存到数组中

  1. $rows = array();

  2. while($row = sqlite_fetch_array($result, $res_type, $decode)) {

  3. $rows[] = $row;
  4. }
  5. ?>
复制代码

附,SQLite Error Constants

SQLITE_OK No error occurred. SQLITE_ERROR SQLite error (or database not found). SQLITE_INTERNAL An internal SQLite error. SQLITE_PERM Access permission denied. SQLITE_ABORT Callback routine aborted. SQLITE_BUSY The database file is currently locked. SQLITE_LOCKED A table within the database is locked. SQLITE_NOMEM SQLite memory allocation error. SQLITE_READONLY An attempt to write to a read-only database. SQLITE_INTERRUPT Interrupted operation. SQLITE_IOERR A file I/O error has occurred. SQLITE_CORRUPT The specified database is corrupted. SQLITE_FULL Database is full. SQLITE_CANTOPEN Could not open database file. SQLITE_PROTOCOL Database lock protocol error. SQLITE_SCHEMA The database schema changed. SQLITE_TOOBIG Too much data for a single row. SQLITE_CONSTRAINT Abort due to constraint violation. SQLITE_MISMATCH Data type mismatch. SQLITE_AUTH Authorization denied. SQLITE_ROW sqlite_step() has another row ready. SQLITE_DONE sqlite_step() has finished executing.


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板