PHP/MySQL Database/sqlite query
Advanced Functions
$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_query.php
<?php
$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);
?>
Using the sqlite_query() Function
<?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);
?>