1

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);
?>

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

when i echo $db; it give me error msh of this Error in query: SQL logic error or missing database so what is this problem and how i resolve it ?
right after the echo $db; line add an exit(); so the script dies and hopefully it will print out the string you are building for the path. You want these lines right after the first $db = line.
0

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.

1 Comment

yes the emty database name that is generated in the folder wamp/www i put the database crated source code put inside it but the issue is gain same it then show the again same msg .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.