问题描述
我有一个用于网站的 SQLite 数据库.问题是当我尝试 INSERT INTO
它时,我得到一个 PDOException
I have a SQLite database that I am using for a website. The problem is that when I try to INSERT INTO
it, I get a PDOException
SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
我通过 SSH 连接到服务器并检查权限,并且数据库具有权限
I SSH'd into the server and checked permissions, and the database has the permissions
-rw-rw-r--
我不太熟悉 *nix 权限,但我很确定这意味着
I'm not that familiar with *nix permissions, but I'm pretty sure this means
- 不是目录
- 所有者具有读/写权限(根据
ls -l
,就是我) - 组具有读/写权限
- 其他人只有读取权限
我还查看了所有我知道使用 sqlite3
程序的地方,但没有发现任何相关内容.
I also looked everywhere I knew to using the sqlite3
program, and found nothing relevant.
因为我不知道 PDO 试图以什么权限打开数据库,所以我知道
Because I didn't know with what permissions PDO is trying to open the database, I did
chmod o+w supplies.db
现在,我得到另一个PDOException
:
SQLSTATE[HY000]: General error: 14 unable to open database file
但它仅在我尝试在数据库打开后执行INSERT
查询时发生.
But it ONLY occurs when I try to execute an INSERT
query after the database is open.
对正在发生的事情有什么想法吗?
推荐答案
事实证明,问题在于 PDO SQLite 驱动程序要求如果您要执行写操作(INSERT
、UPDATE
、DELETE
、DROP
等),那么数据库所在的文件夹必须有写权限,以及实际的数据库文件.
The problem, as it turns out, is that the PDO SQLite driver requires that if you are going to do a write operation (INSERT
,UPDATE
,DELETE
,DROP
, etc), then the folder the database resides in must have write permissions, as well as the actual database file.
我在位于PDO SQLite 驱动程序手册页.
I found this information in a comment at the very bottom of the PDO SQLite driver manual page.
这篇关于插入过程中出现 SQLite 错误“尝试写入只读数据库"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!