Home  >  Article  >  Backend Development  >  Example of php sqlite_query function

Example of php sqlite_query function

WBOY
WBOYOriginal
2016-07-25 08:57:46990browse
  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. ?>
复制代码

例2,使用sqlite查询()函数

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

  2. if(!$db) die("Could 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("Could not insert city " . "'{$city['name']}, {$city['state']}");
  10. }
  11. }
  12. sqlite_close($db);
  13. ?>

复制代码

例3,sqlite_query查询测试

  1. /**
  2. * Test case for sqlite_query query
  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. ?>

复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn