欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php sqlite_query函数的例子

程序员文章站 2022-03-07 21:58:43
...
  1. /**
  2. * sqlite_query函数简单示例
  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. * sqlite_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. ?>
复制代码