Rumah > pembangunan bahagian belakang > tutorial php > php sqlite_query函数的例子

php sqlite_query函数的例子

WBOY
Lepaskan: 2016-07-25 08:57:46
asal
1053 orang telah melayarinya
  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. ?>
复制代码


Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan