无法通过 php 5.3.0 写入 SQlite3 上的 chmod 777 数据库文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1485525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:46:51  来源:igfitidea点击:

Unable to write to a chmod 777 database file on SQlite3 via php 5.3.0

phpsqlsqlite

提问by Mint

I'm trying to insert data into my SQlite3 database (this works via the command line). I gave the data1.db file 777 permissions and still it says it's unable to open the file.

我正在尝试将数据插入到我的 SQlite3 数据库中(这是通过命令行工作的)。我给了 data1.db 文件 777 权限,但它仍然说它无法打开文件。

I get this error:

我收到此错误:

Warning: SQLite3::exec() [sqlite3.exec]: unable to open database file in /var/www/test.php on line 3

Using this code:

使用此代码:

$db = new SQLite3('./data1.db');
$db->exec("INSERT INTO table1 (fileName) VALUES ('test.txt')");

But the strange thing is that I can read from the database: (this works)

但奇怪的是我可以从数据库中读取:(这有效)

print_r($db->querySingle('SELECT fileName FROM table1', true));

I'm running PHP 5.3.0

我正在运行 PHP 5.3.0

回答by Bill Karwin

The folder containing the SQLite file must be writeable by the web user, if you want to make changes to it. It's not enough that the .db file is writeable.

如果您想对其进行更改,包含 SQLite 文件的文件夹必须可由 Web 用户写入。.db 文件是可写的还不够。

See Why can't DBD::SQLite insert into a database through my Perl CGI script?

请参阅为什么 DBD::SQLite 不能通过我的 Perl CGI 脚本插入数据库?

回答by meder omuraliev

Try adding the sqlite user to the group which owns the /var/www directories, or manually chown -R user:user /var/www/ , the directory needs to be writable by the sqlite user.

尝试将 sqlite 用户添加到拥有 /var/www 目录的组,或手动 chown -R user:user /var/www/ ,该目录需要由 sqlite 用户写入。

回答by Thomas Decaux

Pay attention, if you run PHP with CLI, you must use "sudo -u www-data php script.php" so PHP can write on the sqlite.

注意,如果你用 CLI 运行 PHP,你必须使用“sudo -u www-data php script.php”,这样 PHP 才能在 sqlite 上写。