本节内容:
php sqlite_query函数实例。
例1,sqlite_query函数的例子
例2,使用sqlite查询()函数
<?php
$db = sqlite_open(":memory:");
if(!$db) die("Could not create the temporary database");
$query = "CREATE TABLE cities(name VARCHAR(255), state VARCHAR(2))";
sqlite_query($db, $query);
$cities[] = array('name' => 'Chicago','state'=> 'IL');
foreach($cities as $city) {
$query = "INSERT INTO cities VALUES(" ."'{$city['name']}', '{$city['state']}')";
if(!sqlite_query($db, $query)) {
trigger_error("Could not insert city " . "'{$city['name']}, {$city['state']}");
}
}
sqlite_close($db);
?>
例3,sqlite_query查询测试
<?php
/**
* sqlite_query查询的测试用例
* by www.jb200.com
*/
$dbconn = sqlite_open('phpdb');
if ($dbconn) {
script!
sqlite_query($dbconn, "INSERT INTO animal VALUES('a', 14)");
sqlite_query($dbconn, "INSERT INTO animal VALUES('b', 16)");
sqlite_query($dbconn, "INSERT INTO animal VALUES('c', 13)");
var_dump(sqlite_array_query($dbconn, "SELECT * FROM animal", SQLITE_ASSOC));
} else {
print "Connection to database failed!n";
}
?>