Example of phpsqlite_query function

Source: Internet
Author: User
Tags sqlite query
Example of phpsqlite_query function

  1. /**
  2. * Simple example of sqlite_query function
  3. * By bbs.it-home.org
  4. */
  5. $ Sqldb = sqlite_open ("mydatabase. db ");
  6. $ Results = sqlite_query ($ sqldb, "SELECT * FROM employee ");
  7. While (list ($ empid, $ name) = sqlite_fetch_array ($ results )){
  8. Echo "Name: $ name (Employee ID: $ empid)
    ";
  9. }
  10. Sqlite_close ($ sqldb );
  11. ?>

Example 2: Use the sqlite Query () function

  1. $ Db = sqlite_open (": memory :");

  2. If (! $ Db) die ("cocould not create the temporary database ");

  3. $ Query = "create table cities (name VARCHAR (255), state VARCHAR (2 ))";

  4. Sqlite_query ($ db, $ query );
  5. $ Cities [] = array ('name' => 'Chicago ', 'state' => 'Il ');
  6. Foreach ($ cities as $ city ){
  7. $ Query = "insert into cities VALUES (". "'{$ city ['name']}', '{$ city ['state']}')";
  8. If (! Sqlite_query ($ db, $ query )){
  9. Trigger_error ("cocould not insert city". "'{$ city ['name']}, {$ city ['state']}");
  10. }
  11. }
  12. Sqlite_close ($ db );
  13. ?>

Example 3: sqlite_query query test

  1. /**

  2. * Sqlite_query query test cases
  3. * By bbs.it-home.org
  4. */
  5. $ Dbconn = sqlite_open ('phpdb ');

  6. If ($ dbconn ){

  7. Script!
  8. Sqlite_query ($ dbconn, "insert into animal VALUES ('A', 14 )");
  9. Sqlite_query ($ dbconn, "insert into animal VALUES ('B', 16 )");
  10. Sqlite_query ($ dbconn, "insert into animal VALUES ('C', 13 )");
  11. Var_dump (sqlite_array_query ($ dbconn, "SELECT * FROM animal", SQLITE_ASSOC ));
  12. } Else {
  13. Print "Connection to database failed! \ N ";
  14. }
  15. ?>

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.