SQLite error #39;attempt to write a readonly database#39; during insert?(插入过程中出现 SQLite 错误“尝试写入只读数据库?)
问题描述
我有一个用于网站的 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 错误“尝试写入只读数据库"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:插入过程中出现 SQLite 错误“尝试写入只读数据库"?
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
