Reputation: 3098
I'm using this constant loop standalone script to get data from SQLite3 db. Once in a while script exits with fatal error:
PHP Warning: SQLite3::query(): Unable to prepare statement: 14, unable to open database file in /home/alex/looper.php on line 17
PHP Fatal error: Call to a member function fetchArray() on a non-object in /home/alex/looper.php on line 19
There is no much data in that db, maybe 10-50 rows total. Not sure where to start looking. Please help.
Code:
function listen() {
$db = new SQLite3("/home/alex/some.db");
$result = $db->query("SELECT * FROM names where status=0");
while($row = $result->fetchArray()) {
// .... do some stuff and delete record
$db->query("DELETE FROM names WHERE id='$row[id]'");
}
sleep(3);
listen();
}
set_time_limit(0);
listen();
Upvotes: 0
Views: 2455
Reputation: 1106
Another issue is that after you have opened the database, done something you need to then close the database before you can execute another query because you can't open an already opened database... its open!
Your example, for the life of me I can not think what type of real world scenario would exist where a function calls itself repeatedly but anyway... it raises concerns for your neighbors on your web host's server as your website will be sharing hosting space with others...
if you are using set_time_limit(0); then your script is going to hog all the CPU time and others sites will suffer for it, unless you are the sole owner of a hosting server, you should not set time limits that mean that the script has no limitation.
Suggested reading : http://php.net/manual/en/function.set-time-limit.php
Upvotes: 0
Reputation: 17797
Pretty self explanatory. the database file cannot be opened. either it is not there (try a full path, keep case sensitivity in mind) or the server has not enough rights to open it (the webserver runs usually under its own user account, which most likely is different than the owner of the file).
Upvotes: 1