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

匿名 (未验证) 提交于 2019-12-03 01:06:02

问题:

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.

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

回答1:

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.

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



回答2:

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.



回答3:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!