0、问题描述
使用PHP操作SQLite的时候发现执行
public SQLite3::exec(string $query): bool
方法时存在问题,查看/var/log/apache2/error.log的日志发现如下提示
[Mon Feb 07 18:17:45.867326 2022] [php7:warn] [pid 30124]
[client 120.242.4.136:13034]
PHP Warning: SQLite3::exec(): attempt to write a readonly database in
通过尝试给Sqlite数据库文件适当的权限,用户组,拥有者均无效,无奈官网查看手册发现 https://www.php.net/manual/en/sqlite3.exec.php
Note: SQLite3 may need to create » temporary files during the execution of queries, so the respective directories may have to be writable.
也是服了,Sqlite 在执行写操作的时候需要在数据库的同级目录下生成临时文件,所以该目录页需要可写的权限!
1、解决方法
给SQLite数据库所在的目录写权限。
参考
- https://www.php.net/manual/en/sqlite3.exec.php