Heim  >  Artikel  >  Backend-Entwicklung  >  php sqlite_query函数的例子

php sqlite_query函数的例子

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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn