I'm struggling all morning to make php work with an sqlite database. Here is a piece of php code that I try to execute:
#less /var/www/html/test.php <?php $db=new PDO("sqlite:/var/www/test.sql"); $sql = "insert into test (login,pass) values ('login','pass');"; $db->exec($sql); ?>
Here is how I've done tests:
# sqlite3 /var/www/test.sql sqlite> create table test (login varchar,pass varchar); #chown apache:apache /var/www/test.sql #chmod 644 /var/www/test.sql
Here is the stuff that drives me mad: When I execute from command line:
everything goes well. Sql is being executed and I can see a new row appear in the database.
When I execute the same script from a browser - sql is not being executed. I don't get a new row in the database. There are no errors in the apache log file.
Ok, I've got the answer. It looks like sqlite is trying to create a new -journal file on "INSERT" query. strace rocks:
open("/var/www/test.sql-journal", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0644) = -1 EACCES (Permission denied)
So, I had to move sqlite database to a directory, apache could write to.