我有许多网页愉快地工作,以不同的方式选择,更新,插入和删除数据库值。然而,当我从一个表中选择一些数据然后直接更新它时,我在一个特定的PHP页面上遇到了一个问题。
testdb
在一个名为
monitoring
CREATE TABLE IF NOT EXISTS testdb ('name' TEXT NOT NULL, 'color' TEXT, 'schedule' INTEGER NOT NULL);
然后我添加了一行随机值;
INSERT INTO testdb (name, color, schedule) VALUES ("testing","green",2);
下面是导致504网关超时的示例PHP代码
// select a row in testdb
$db = new PDO('sqlite:/srv/monitoring/monitoring');
$stmt = $db->prepare("SELECT color FROM testdb WHERE name='testing';");
$stmt->execute();
$result = $stmt->fetch();
$db = null;
echo $result['color'];
// Update testdb
$db = new PDO('sqlite:/srv/monitoring/monitoring');
$sql = "UPDATE testdb SET color = 'green', schedule = 2 WHERE name = 'testing'";
$stmt = $db -> prepare($sql);
$stmt -> execute();
$db = null;
?>
我可以单独运行SELECT块或UPDATE块,它们都可以工作(我可以通过从命令行检查表来确认这一点,因此数据库没有权限或访问问题)。但是如果我试图像正常页面一样加载页面,就会出现超时。
我怀疑这是我搞砸了的简单而愚蠢的事情,但如果我看到它,我就该死了。