简体   繁体   English

循环SQLite3查询时发生PHP错误

[英]PHP error when looping SQLite3 query

I'm using this constant loop standalone script to get data from SQLite3 db. 我正在使用此恒定循环独立脚本从SQLite3数据库获取数据。 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. 该数据库中没有太多数据,总共可能有10至50行。 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();

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). 它可能不存在(尝试使用完整路径,请注意区分大小写),或者服务器没有足够的权限打开它(网络服务器通常以其自己的用户帐户运行,这很可能与文件所有者不同) 。

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); 如果您正在使用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. 那么您的脚本将占用所有CPU时间,并且其他站点将为此遭受损失,除非您是托管服务器的唯一所有者,否则不应设置时间限制,这意味着该脚本没有限制。

Suggested reading : http://php.net/manual/en/function.set-time-limit.php 建议阅读: http : //php.net/manual/en/function.set-time-limit.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM