I am trying to make a connection to SQLite using PHP.(I am basically trying to browse through the database of Spiceworks which is on my system.)
My PHP code works fine till sqlite_open. But it does not proceed beyond SQLITE_OPEN.
What could the problem be? How do I correct it? My code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<?php
// set path of database file
echo "Hello!";
$db = "C:\Program Files (x86)\Spiceworks\db\spiceworks_prod.db";
// open database file
$handle = sqlite_open($db) or die("Could not open database");
// generate query string
$query = "SELECT * FROM devices";
// execute query
$result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
// if rows exist
if (sqlite_num_rows($result) > 0) {
// get each row as an array
// print values
echo "<table cellpadding=10 border=1>";
while($row = sqlite_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
}
echo "</table>";
}
// all done
// close database file
sqlite_close($handle);
?>
</body>
</html>
It could be because the route of the database, why don't you try to use $_SERVER['DOCUMENT_ROOT']
or something similar and take this as your path to the database?