首页 > 后端开发 > php教程 > php sqlite_query函数的例子

php sqlite_query函数的例子

WBOY
发布: 2016-07-25 08:57:46
原创
1051 人浏览过
  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. ?>
复制代码


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板