Reputation: 95
This is my source code in which I used SQLite database in my PHP source code. When I run the script it give me this error
Warning: sqlite_query() [function.sqlite-query]: no such table:
books in D:\wamp\www\sqllite\index.php on line 13
Error in query: SQL logic error or missing database
I think the error is at the path of database
<?php
$db = $_SERVER['DOCUMENT_ROOT']."umer.db";
$handle = sqlite_open($db) or die("Could not open database".sqlite_error_string(sqlite_last_error($handle)));
$query = "SELECT * FROM books";
$result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
if (sqlite_num_rows($result) > 0) {
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>";
}
sqlite_close($handle);
?>
Upvotes: 1
Views: 2544
Reputation: 27478
php will start looking for the database file relative to the directory where the currently running file came from so constructs like("../../databases/mydb.sq3") are usually more portable than using an absolute path or a path relative to DOCUMENT_ROOT as these can be changed at a whim.
Your program is almost certainly not finding the database file, in these circumstances sqlite will create a new empty file, and, causes great confusion by raising a "table not found" error when you try to use the database.
Look for an empty "umber.db" appearing somewhere unexpected and this will give you some indication of where you are going wrong.
Upvotes: 0
Reputation: 1408
The error is probably the path, which is determined by this line:
$db = $_SERVER['DOCUMENT_ROOT']."umer.db";
To troubleshoot this you should try an
echo $db;
And then compare that to your actual path - from there you should be able to adjust your string.
If the path is still correct, double check your file permissions and make sure it is readable by the user that is running the php process.
Good luck!
Upvotes: 1