-
-
/**
- * sqlite_query函数简单示例
- * by bbs.it-home.org
- */
- $sqldb = sqlite_open("mydatabase.db");
- $results = sqlite_query($sqldb, "SELECT * FROM employee");
- while (list($empid, $name) = sqlite_fetch_array($results)) {
- echo "Name: $name (Employee ID: $empid)
";
- }
- sqlite_close($sqldb);
- ?>
复制代码
例2,使用sqlite查询()函数
-
-
$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查询测试
-
-
/**
- * sqlite_query查询的测试用例
- * by bbs.it-home.org
- */
- $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";
- }
- ?>
-
复制代码
|