Click here to get back home

PHP unable to open database file

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
PHP unable to open database file Tim Streater 07-11-2008
Get Chitika Premium
Posted by Tim Streater on July 11, 2008, 1:43 pm
Please log in for more thread options
I have this script of a few lines, which runs as expected when I do it
from the command line. It does one select followed by one insert on an
SQLite database. The db in question has permissions guo+rwx.

If I run it as a web page (this is under OS X Leopard), the select works
but the insert fails with this exception:

SQLSTATE[HY000]: General error: 14 unable to open database file

Any reason PHP cannot write to a file from apache?

Here is the script:


$dbh = new PDO ("sqlite:/opsdb");

$dbh->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$resq = $dbh->query ("select firstname from contact where absid=1");
$resn = $resq->fetchAll ();
echo "Name = '" . $resn[0]["firstname"] . "'<br>\n<br>\n";

$res = $dbh->query ("insert into contact (absid) values (null)");
$absid = $dbh->lastInsertId ();

echo "absid='" . $absid . "'<br>\n";

Thanks -- tim

Posted by The Natural Philosopher on July 11, 2008, 6:40 pm
Please log in for more thread options
Tim Streater wrote:
> I have this script of a few lines, which runs as expected when I do it
> from the command line. It does one select followed by one insert on an
> SQLite database. The db in question has permissions guo+rwx.
>
> If I run it as a web page (this is under OS X Leopard), the select works
> but the insert fails with this exception:
>
> SQLSTATE[HY000]: General error: 14 unable to open database file
>
> Any reason PHP cannot write to a file from apache?
>
> Here is the script:
>
>
> $dbh = new PDO ("sqlite:/opsdb");
>
> $dbh->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>
> $resq = $dbh->query ("select firstname from contact where absid=1");
> $resn = $resq->fetchAll ();
> echo "Name = '" . $resn[0]["firstname"] . "'<br>\n<br>\n";
>
> $res = $dbh->query ("insert into contact (absid) values (null)");
> $absid = $dbh->lastInsertId ();
>
> echo "absid='" . $absid . "'<br>\n";
>
> Thanks -- tim
Not sure its relevant, but apache runs as a different user than you
running code on the command line.

Posted by Tim Streater on July 11, 2008, 7:01 pm
Please log in for more thread options

> Tim Streater wrote:
> > I have this script of a few lines, which runs as expected when I do it
> > from the command line. It does one select followed by one insert on an
> > SQLite database. The db in question has permissions guo+rwx.
> >
> > If I run it as a web page (this is under OS X Leopard), the select works
> > but the insert fails with this exception:
> >
> > SQLSTATE[HY000]: General error: 14 unable to open database file
> >
> > Any reason PHP cannot write to a file from apache?
> >
> > Here is the script:
> >
> >
> > $dbh = new PDO ("sqlite:/opsdb");
> >
> > $dbh->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
> >
> > $resq = $dbh->query ("select firstname from contact where absid=1");
> > $resn = $resq->fetchAll ();
> > echo "Name = '" . $resn[0]["firstname"] . "'<br>\n<br>\n";
> >
> > $res = $dbh->query ("insert into contact (absid) values (null)");
> > $absid = $dbh->lastInsertId ();
> >
> > echo "absid='" . $absid . "'<br>\n";
> >
> > Thanks -- tim
> Not sure its relevant, but apache runs as a different user than you
> running code on the command line.

Right. But as I mentioned, permissions are guo+rwx, so it should be
read/write for anyone.

Posted by The Natural Philosopher on July 11, 2008, 7:18 pm
Please log in for more thread options
Tim Streater wrote:
>
>> Tim Streater wrote:
>>> I have this script of a few lines, which runs as expected when I do it
>>> from the command line. It does one select followed by one insert on an
>>> SQLite database. The db in question has permissions guo+rwx.
>>>
>>> If I run it as a web page (this is under OS X Leopard), the select works
>>> but the insert fails with this exception:
>>>
>>> SQLSTATE[HY000]: General error: 14 unable to open database file
>>>
>>> Any reason PHP cannot write to a file from apache?
>>>
>>> Here is the script:
>>>
>>>
>>> $dbh = new PDO ("sqlite:/opsdb");
>>>
>>> $dbh->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>>>
>>> $resq = $dbh->query ("select firstname from contact where absid=1");
>>> $resn = $resq->fetchAll ();
>>> echo "Name = '" . $resn[0]["firstname"] . "'<br>\n<br>\n";
>>>
>>> $res = $dbh->query ("insert into contact (absid) values (null)");
>>> $absid = $dbh->lastInsertId ();
>>>
>>> echo "absid='" . $absid . "'<br>\n";
>>>
>>> Thanks -- tim
>> Not sure its relevant, but apache runs as a different user than you
>> running code on the command line.
>
> Right. But as I mentioned, permissions are guo+rwx, so it should be
> read/write for anyone.

Try su-ing to the apache user and see if it still works, anyway.


Similar ThreadsPosted
fopen() unable to open some URLs? August 11, 2005, 3:51 pm
unable to open socket connections on select ports? May 14, 2006, 11:44 pm
PHP:Unable to post variables from html form to mysql database September 29, 2004, 1:23 pm
Unable to write a file in a directory that my PHP script creates November 15, 2005, 10:24 am
File Upload issue - Unable to Upload a Large File November 29, 2006, 4:31 pm
Open .php file with PHP Designer 2007 by clicking the file in XP November 25, 2006, 9:27 am
how do you open a file with quote marks in the file name on Linux? October 18, 2007, 8:38 pm
how do I tell a browser the name of a file, for download, if the file has open space in its name? October 20, 2007, 5:32 am
Open a new php file April 2, 2006, 4:10 pm
Cannot open file December 2, 2006, 9:21 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap