php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34699 PDO's sqlite driver unable to write to database
Submitted: 2005-10-01 12:24 UTC Modified: 2005-10-02 22:36 UTC
From: aidan@php.net Assigned:
Status: Closed Package: PDO related
PHP Version: 6CVS-2005-10-01 (CVS) OS: Linux
Private report: No CVE-ID: None
 [2005-10-01 12:24 UTC] aidan@php.net
Description:
------------
In PHP6, PDO seems unable to write to a sqlite database. 

However, just to make it interesting, it's only a problem when the script is executed by the webserver (in my case apache). 

Initially I thought it was a permissions issue, but the database file was 666.

Running the script from CLI worked as expected, running it from the webserver produced the error:
Warning: PDO::query() [function.query]: SQLSTATE[HY000]: General error: 1 unable to open database file

Confusing, because the database file is already open as demonstrated by the successful query of the same table in the previous line.

Reproduce code:
---------------
<?php
$db = new PDO('sqlite:repository.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

$res = $db->query('SELECT visits from pages where id=1');
$tml = $res->fetchAll();
echo $tml[0][0], "\n";


$db->query('UPDATE pages SET visits = visits+1 WHERE id =1');


Expected result:
----------------
23324

Actual result:
--------------
23324
Warning: PDO::query() [function.query]: SQLSTATE[HY000]: General error: 1 unable to open database file in /home/aidan/public_html/repos/database/test.php on line 10

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-01 12:29 UTC] aidan@php.net
Ah, it is a permissions issue. The directory must have write permissions too.

I'll add this as a note into the docs, and close the bug.

Perhaps it would be possible Wez, for the sqlite driver to give a more specific error?
 [2005-10-02 22:36 UTC] wez@php.net
The PDO driver has no more of an idea of the cause than you do; it's passing back the error information from sqlite.  You're better off asking the sqlite guys to make their error messages a bit more human friendly :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 03:01:28 2024 UTC