PHP access to the SQLite database example

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

Copy Code

Example 2, saving the result set to an array

    1. $rows = Array ();

    2. while ($row = Sqlite_fetch_array ($result, $res _type, $decode)) {

    3. $rows [] = $row;
    4. }
    5. ?>
Copy Code

Attached, 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 a 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.
  • 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.