本节内容:
php sqlite_query函数实例。
例1,sqlite_query函数的例子
/**
* sqlite_query函数简单示例
* by www.
*/
$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) <br />";
}
sqlite_close($sqldb);
?>
例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.
*/
$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";
}
?>
本节内容:
sqlite_create_function函数的例子
例子:
<?php
/**
* sqlite_create_function函数示例
* edit: www.
*/
define("PPO",400);
function my($salary){
return $salary / PPO;
}
$sqldb = sqlite_open("mydatabase.db");
sqlite_create_function($sqldb,"myFunction", "my", 1);
$query = "select myFunction(salary) FROM employee WHERE empid=1";
$result = sqlite_query($sqldb, $query);
list($myFunction) = sqlite_fetch_array($result);
echo "The employee can purchase: ".$myFunction." ounces.";
sqlite_close($sqldb);
?>
例子:
/**
* sqlite_num_fields函数举例
* edit: www.
*
*/
$sqldb = sqlite_open("mydatabase.db");
$results = sqlite_query($sqldb, "SELECT * FROM employee");
echo "Total fields returned: ".sqlite_num_fields($results)."<br />";
sqlite_close($sqldb);
?>