插入期间出现SQLite错误“试图编写只读数据库"? [英] SQLite error 'attempt to write a readonly database' during insert?

查看:291
本文介绍了插入期间出现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,就是我)
  • 该组具有读/写权限
  • 其他人仅具有读取权限
  • Not a directory
  • Owner has read/write permissions (that's me, according to ls -l)
  • Group has read/write permissions
  • Everyone else only has read permissions

我也到处了解使用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驱动程序要求您执行写操作(INSERTUPDATEDELETEDROP等),那么数据库所在的文件夹必须具有写权限以及实际的数据库文件.

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驱动程序手册页.

这篇关于插入期间出现SQLite错误“试图编写只读数据库"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆