Can"t open SQLite DB... but only when using mod_php??

Can"t open SQLite DB... but only when using mod_php??

am 02.10.2007 19:53:43 von Markus Wolff - NorthClick

Hey there,

I'm trying to open an SQLite3 database from a PHP very simple PHP
script:

$db = dirname(__FILE__).'/frontend.db';
$pdo = new PDO('sqlite:'.$db);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->query("SELECT * FROM page LIMIT 1");
echo "Deleting pages\n";
$pdo->query("DELETE FROM page");
echo "Deleting websites\n";
$pdo->query("DELETE FROM website");

The database file contains no data whatsoever, just the table
definitions (in case you were wondering, this is a stripped-down version
of a larger script for debugging purposes, hence the seemingly idiotic
DELETE statements that won't do any good in an empty database anyway,
but I digress...).

When executed on the command line, this works perfectly. When I execute
the same script via Apache and mod_php, I'm getting this exception:

PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
missing database in /home/mwolff/webs/markus/cms/test.php on line 8

Getting experimental, I've tried to change the calls for the DELETE
statements from $pdo->query() to $pdo->exec(), just to see what happens.
Well, what happens is that I'm getting a different error:

PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
file in /home/mwolff/webs/markus/cms/test.php on line 6

Argh... what can possibly be wrong here? The script works from the
commandline, with the exact same PHP version (Debian package, PHP
5.2.0-8+etch7, and we also tried upgrading to the latest Debian package
of 5.2.4, to no avail).

It can't be file permissions, I've even tried to set the database file
to 777... no change at all.

Does this ring a bell with anyone here?

Thanks,
Markus

--
Mit freundlichen Grüßen
Markus Wolff
Development

NorthClick GmbH

Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Internet: http://www.northclick.de/

Geschäftsführer: F. Detzner | M. Henze | C. Springub
Amtsgericht Hamburg, HRB 94459

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 02:34:23 von dmagick

Markus Wolff - NorthClick wrote:
> Hey there,
>
> I'm trying to open an SQLite3 database from a PHP very simple PHP
> script:
>
> $db = dirname(__FILE__).'/frontend.db';
> $pdo = new PDO('sqlite:'.$db);
> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
> $pdo->query("SELECT * FROM page LIMIT 1");
> echo "Deleting pages\n";
> $pdo->query("DELETE FROM page");
> echo "Deleting websites\n";
> $pdo->query("DELETE FROM website");
>
> The database file contains no data whatsoever, just the table
> definitions (in case you were wondering, this is a stripped-down version
> of a larger script for debugging purposes, hence the seemingly idiotic
> DELETE statements that won't do any good in an empty database anyway,
> but I digress...).
>
> When executed on the command line, this works perfectly. When I execute
> the same script via Apache and mod_php, I'm getting this exception:
>
> PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
> missing database in /home/mwolff/webs/markus/cms/test.php on line 8
>
> Getting experimental, I've tried to change the calls for the DELETE
> statements from $pdo->query() to $pdo->exec(), just to see what happens.
> Well, what happens is that I'm getting a different error:
>
> PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
> file in /home/mwolff/webs/markus/cms/test.php on line 6
>
> Argh... what can possibly be wrong here? The script works from the
> commandline, with the exact same PHP version (Debian package, PHP
> 5.2.0-8+etch7, and we also tried upgrading to the latest Debian package
> of 5.2.4, to no avail).
>
> It can't be file permissions, I've even tried to set the database file
> to 777... no change at all.

My guess is still permissions. If you try a raw fopen instead of using
pdo, what happens?

error_reporting(E_ALL);
ini_set('display_errors', true);
$fp = fopen(dirname(__FILE__).'/frontend.db', 'r');
if ($fp) {
echo "Opened db
\n";
} else {
echo "Unable to open db
\n";
}
fclose($fp);
?>

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 12:26:43 von Goltsios Theodore

Well the directory that houses the database should be writable.
Running the script from command line it gives you write access probably
but it won't work using mod_php because the web server probably can't
write. Try it and give us some feedback.

--
Thodoris



O/H Chris έγραψε:
> Markus Wolff - NorthClick wrote:
>> Hey there,
>>
>> I'm trying to open an SQLite3 database from a PHP very simple PHP
>> script:
>>
>> $db = dirname(__FILE__).'/frontend.db';
>> $pdo = new PDO('sqlite:'.$db);
>> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>> $pdo->query("SELECT * FROM page LIMIT 1");
>> echo "Deleting pages\n"; $pdo->query("DELETE FROM page");
>> echo "Deleting websites\n";
>> $pdo->query("DELETE FROM website");
>>
>> The database file contains no data whatsoever, just the table
>> definitions (in case you were wondering, this is a stripped-down version
>> of a larger script for debugging purposes, hence the seemingly idiotic
>> DELETE statements that won't do any good in an empty database anyway,
>> but I digress...).
>>
>> When executed on the command line, this works perfectly. When I execute
>> the same script via Apache and mod_php, I'm getting this exception:
>>
>> PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
>> missing database in /home/mwolff/webs/markus/cms/test.php on line 8
>>
>> Getting experimental, I've tried to change the calls for the DELETE
>> statements from $pdo->query() to $pdo->exec(), just to see what happens.
>> Well, what happens is that I'm getting a different error:
>>
>> PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
>> file in /home/mwolff/webs/markus/cms/test.php on line 6
>>
>> Argh... what can possibly be wrong here? The script works from the
>> commandline, with the exact same PHP version (Debian package, PHP
>> 5.2.0-8+etch7, and we also tried upgrading to the latest Debian package
>> of 5.2.4, to no avail).
>>
>> It can't be file permissions, I've even tried to set the database file
>> to 777... no change at all.
>
> My guess is still permissions. If you try a raw fopen instead of using
> pdo, what happens?
>
> > error_reporting(E_ALL);
> ini_set('display_errors', true);
> $fp = fopen(dirname(__FILE__).'/frontend.db', 'r');
> if ($fp) {
> echo "Opened db
\n";
> } else {
> echo "Unable to open db
\n";
> }
> fclose($fp);
> ?>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 17:45:07 von Markus Wolff - NorthClick

Chris schrieb:
>> It can't be file permissions, I've even tried to set the database file
>> to 777... no change at all.
>
> My guess is still permissions. If you try a raw fopen instead of using
> pdo, what happens?
>
> > error_reporting(E_ALL);
> ini_set('display_errors', true);
> $fp = fopen(dirname(__FILE__).'/frontend.db', 'r');
> if ($fp) {
> echo "Opened db
\n";
> } else {
> echo "Unable to open db
\n";
> }
> fclose($fp);
> ?>

Hey Chris,

mmh wonder what could possibly be wrong when even trying 777? :-)

Anyway, just to make sure (and because I'm desperate enough to grasp for
straws right now), I tried exacly what you proposed and it still yields
the same results.

Thanks for your suggestion anyway, sometimes one forgets to try the most
obvious things first :-)

CU
Markus


--
Markus Wolff
-Development-

NorthClick GmbH

Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Internet: http://www.northclick.de/

Geschäftsführer: F. Detzner | M. Henze | C. Springub Amtsgericht Hamburg,
HRB 94459

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 18:43:26 von Goltsios Theodore

--------------060105000407030707020502
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

I run into this:
http://www.php.net/manual/en/ref.pdo-sqlite.php

while searching for a solution to this exception:
PDOException: SQLSTATE[HY000]: General error: 1

Take a look at it bacause this might be happenning due to version
incompatibilities. For example only sqlite version 3.1.4 and after can
read file formats 1,2 and 3. Is you database format new?|
|

--
Thodoris


O/H Markus Wolff έγραψε:
> Chris schrieb:
>>> It can't be file permissions, I've even tried to set the database file
>>> to 777... no change at all.
>>
>> My guess is still permissions. If you try a raw fopen instead of
>> using pdo, what happens?
>>
>> >> error_reporting(E_ALL);
>> ini_set('display_errors', true);
>> $fp = fopen(dirname(__FILE__).'/frontend.db', 'r');
>> if ($fp) {
>> echo "Opened db
\n";
>> } else {
>> echo "Unable to open db
\n";
>> }
>> fclose($fp);
>> ?>
>
> Hey Chris,
>
> mmh wonder what could possibly be wrong when even trying 777? :-)
>
> Anyway, just to make sure (and because I'm desperate enough to grasp for
> straws right now), I tried exacly what you proposed and it still yields
> the same results.
>
> Thanks for your suggestion anyway, sometimes one forgets to try the most
> obvious things first :-)
>
> CU
> Markus
>

--------------060105000407030707020502--

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 18:45:45 von Markus Wolff - NorthClick

Hey there,

I've double-checked on three different machines now, and I'm always
getting the same error. All having different versions of PHP, Apache,
PDO and SQLite. So I figure it must be something that I'm doing wrong. I
just can't figure out what it is - and I'm puzzled because I had used
SQLite before (although briefly) and don't think I'm doing anything
different than before.

Anyway, here's what I'm doing, step-by-step:

# sqlite3 frontend.db

Here I insert the following SQL script:

CREATE TABLE website (
website_id INTEGER PRIMARY KEY,
always_expand INTEGER
);

CREATE TABLE page (
page_id INTEGER NOT NULL PRIMARY KEY,
parent_id INTEGER,
website_id INTEGER NOT NULL,
title TEXT,
link TEXT,
depth INTEGER,
visible INTEGER,
element_id INTEGER,
nav_path TEXT,
protected INTEGER,
sort_order INTEGER
);

Then I exit the client and make the PHP script:

# nano test.php

The content of the script still being that of my original message.
Then I adjust the rights:

# chown apache:apache frontend.db
# chmod 777 frontend.db

Then I execute the script on the command line:

# php test.php

No error.

Then I call the script on the website, one of the examples being:
http://www.21st.de/test.php

The script still manages to open the database and do a SELECT query, but
throws the said exception when trying to do the DELETE statement.

These are all the steps that are involved to reproduce the error on
three machines. No more, no less. Now, have I overlooked anything? Am I
missing something really, really stupid? Or is it some kind of a bug?
But certainly that could not have gone unnoticed for so long? (Tested on
PHP versions 5.1.4, 5.2.0 and 5.2.4).

CU
Markus

Markus Wolff - NorthClick schrieb:
> Hey there,
>
> I'm trying to open an SQLite3 database from a PHP very simple PHP
> script:
>
> $db = dirname(__FILE__).'/frontend.db';
> $pdo = new PDO('sqlite:'.$db);
> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
> $pdo->query("SELECT * FROM page LIMIT 1");
> echo "Deleting pages\n";
> $pdo->query("DELETE FROM page");
> echo "Deleting websites\n";
> $pdo->query("DELETE FROM website");
>
> The database file contains no data whatsoever, just the table
> definitions (in case you were wondering, this is a stripped-down version
> of a larger script for debugging purposes, hence the seemingly idiotic
> DELETE statements that won't do any good in an empty database anyway,
> but I digress...).
>
> When executed on the command line, this works perfectly. When I execute
> the same script via Apache and mod_php, I'm getting this exception:
>
> PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
> missing database in /home/mwolff/webs/markus/cms/test.php on line 8
>
> Getting experimental, I've tried to change the calls for the DELETE
> statements from $pdo->query() to $pdo->exec(), just to see what happens.
> Well, what happens is that I'm getting a different error:
>
> PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
> file in /home/mwolff/webs/markus/cms/test.php on line 6
>
> Argh... what can possibly be wrong here? The script works from the
> commandline, with the exact same PHP version (Debian package, PHP
> 5.2.0-8+etch7, and we also tried upgrading to the latest Debian package
> of 5.2.4, to no avail).
>
> It can't be file permissions, I've even tried to set the database file
> to 777... no change at all.
>
> Does this ring a bell with anyone here?
>
> Thanks,
> Markus
>

--
Markus Wolff
-Development-

NorthClick GmbH

Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Internet: http://www.northclick.de/

Geschäftsführer: F. Detzner | M. Henze | C. Springub Amtsgericht Hamburg,
HRB 94459

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 18:55:22 von Goltsios Theodore

--------------080206070007020202040101
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hey Markus,
You should try to "chown apache:apache" and "chmod +w" to the directory
that includes frontend.db . And the link that I posted says:

|/*
** file_format==1 Version 3.0.0.
** file_format==2 Version 3.1.3.
** file_format==3 Version 3.1.4.
**
** Version 3.0 can only use files with file_format==1. Version 3.1.3
** can read and write files with file_format==1 or file_format==2.
** Version 3.1.4 can read and write file formats 1, 2 and 3.
*/

Meaning that not all sqlite3 versions support all file formats. That is
why you should check the version of sqlite.
|

--
Thodoris




O/H Markus Wolff έγραψε:
> Hey there,
>
> I've double-checked on three different machines now, and I'm always
> getting the same error. All having different versions of PHP, Apache,
> PDO and SQLite. So I figure it must be something that I'm doing wrong.
> I just can't figure out what it is - and I'm puzzled because I had
> used SQLite before (although briefly) and don't think I'm doing
> anything different than before.
>
> Anyway, here's what I'm doing, step-by-step:
>
> # sqlite3 frontend.db
>
> Here I insert the following SQL script:
>
> CREATE TABLE website (
> website_id INTEGER PRIMARY KEY,
> always_expand INTEGER
> );
>
> CREATE TABLE page (
> page_id INTEGER NOT NULL PRIMARY KEY,
> parent_id INTEGER,
> website_id INTEGER NOT NULL,
> title TEXT,
> link TEXT,
> depth INTEGER,
> visible INTEGER,
> element_id INTEGER,
> nav_path TEXT,
> protected INTEGER,
> sort_order INTEGER
> );
>
> Then I exit the client and make the PHP script:
>
> # nano test.php
>
> The content of the script still being that of my original message.
> Then I adjust the rights:
>
> # chown apache:apache frontend.db
> # chmod 777 frontend.db
>
> Then I execute the script on the command line:
>
> # php test.php
>
> No error.
>
> Then I call the script on the website, one of the examples being:
> http://www.21st.de/test.php
>
> The script still manages to open the database and do a SELECT query,
> but throws the said exception when trying to do the DELETE statement.
>
> These are all the steps that are involved to reproduce the error on
> three machines. No more, no less. Now, have I overlooked anything? Am
> I missing something really, really stupid? Or is it some kind of a
> bug? But certainly that could not have gone unnoticed for so long?
> (Tested on PHP versions 5.1.4, 5.2.0 and 5.2.4).
>
> CU
> Markus
>
> Markus Wolff - NorthClick schrieb:
>> Hey there,
>>
>> I'm trying to open an SQLite3 database from a PHP very simple PHP
>> script:
>>
>> $db = dirname(__FILE__).'/frontend.db';
>> $pdo = new PDO('sqlite:'.$db);
>> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>> $pdo->query("SELECT * FROM page LIMIT 1");
>> echo "Deleting pages\n"; $pdo->query("DELETE FROM page");
>> echo "Deleting websites\n";
>> $pdo->query("DELETE FROM website");
>>
>> The database file contains no data whatsoever, just the table
>> definitions (in case you were wondering, this is a stripped-down version
>> of a larger script for debugging purposes, hence the seemingly idiotic
>> DELETE statements that won't do any good in an empty database anyway,
>> but I digress...).
>>
>> When executed on the command line, this works perfectly. When I execute
>> the same script via Apache and mod_php, I'm getting this exception:
>>
>> PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
>> missing database in /home/mwolff/webs/markus/cms/test.php on line 8
>>
>> Getting experimental, I've tried to change the calls for the DELETE
>> statements from $pdo->query() to $pdo->exec(), just to see what happens.
>> Well, what happens is that I'm getting a different error:
>>
>> PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
>> file in /home/mwolff/webs/markus/cms/test.php on line 6
>>
>> Argh... what can possibly be wrong here? The script works from the
>> commandline, with the exact same PHP version (Debian package, PHP
>> 5.2.0-8+etch7, and we also tried upgrading to the latest Debian package
>> of 5.2.4, to no avail).
>>
>> It can't be file permissions, I've even tried to set the database file
>> to 777... no change at all.
>>
>> Does this ring a bell with anyone here?
>>
>> Thanks,
>> Markus
>>
>

--------------080206070007020202040101--

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 19:06:13 von Markus Wolff - NorthClick

Hi Thodoris,

I've checked on one of the three boxes now and the SQLite version used
by both the commandline client and PDO is 3.2.8. I know the other two
boxes have different versions, but I always created the database anew on
each box.

I also tried chown/chmod on the parent directory, no change.

CU
Markus

Thodoris schrieb:
> Hey Markus,
> You should try to "chown apache:apache" and "chmod +w" to the directory
> that includes frontend.db . And the link that I posted says:
>
> |/*
> ** file_format==1 Version 3.0.0.
> ** file_format==2 Version 3.1.3.
> ** file_format==3 Version 3.1.4.
> **
> ** Version 3.0 can only use files with file_format==1. Version 3.1.3
> ** can read and write files with file_format==1 or file_format==2.
> ** Version 3.1.4 can read and write file formats 1, 2 and 3.
> */
>
> Meaning that not all sqlite3 versions support all file formats. That is
> why you should check the version of sqlite.
> |
>
> --
> Thodoris
>
>
>
>
> O/H Markus Wolff έγραψε:
>> Hey there,
>>
>> I've double-checked on three different machines now, and I'm always
>> getting the same error. All having different versions of PHP, Apache,
>> PDO and SQLite. So I figure it must be something that I'm doing wrong.
>> I just can't figure out what it is - and I'm puzzled because I had
>> used SQLite before (although briefly) and don't think I'm doing
>> anything different than before.
>>
>> Anyway, here's what I'm doing, step-by-step:
>>
>> # sqlite3 frontend.db
>>
>> Here I insert the following SQL script:
>>
>> CREATE TABLE website (
>> website_id INTEGER PRIMARY KEY,
>> always_expand INTEGER
>> );
>>
>> CREATE TABLE page (
>> page_id INTEGER NOT NULL PRIMARY KEY,
>> parent_id INTEGER,
>> website_id INTEGER NOT NULL,
>> title TEXT,
>> link TEXT,
>> depth INTEGER,
>> visible INTEGER,
>> element_id INTEGER,
>> nav_path TEXT,
>> protected INTEGER,
>> sort_order INTEGER
>> );
>>
>> Then I exit the client and make the PHP script:
>>
>> # nano test.php
>>
>> The content of the script still being that of my original message.
>> Then I adjust the rights:
>>
>> # chown apache:apache frontend.db
>> # chmod 777 frontend.db
>>
>> Then I execute the script on the command line:
>>
>> # php test.php
>>
>> No error.
>>
>> Then I call the script on the website, one of the examples being:
>> http://www.21st.de/test.php
>>
>> The script still manages to open the database and do a SELECT query,
>> but throws the said exception when trying to do the DELETE statement.
>>
>> These are all the steps that are involved to reproduce the error on
>> three machines. No more, no less. Now, have I overlooked anything? Am
>> I missing something really, really stupid? Or is it some kind of a
>> bug? But certainly that could not have gone unnoticed for so long?
>> (Tested on PHP versions 5.1.4, 5.2.0 and 5.2.4).
>>
>> CU
>> Markus
>>
>> Markus Wolff - NorthClick schrieb:
>>> Hey there,
>>>
>>> I'm trying to open an SQLite3 database from a PHP very simple PHP
>>> script:
>>>
>>> $db = dirname(__FILE__).'/frontend.db';
>>> $pdo = new PDO('sqlite:'.$db);
>>> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>>> $pdo->query("SELECT * FROM page LIMIT 1");
>>> echo "Deleting pages\n"; $pdo->query("DELETE FROM page");
>>> echo "Deleting websites\n";
>>> $pdo->query("DELETE FROM website");
>>>
>>> The database file contains no data whatsoever, just the table
>>> definitions (in case you were wondering, this is a stripped-down version
>>> of a larger script for debugging purposes, hence the seemingly idiotic
>>> DELETE statements that won't do any good in an empty database anyway,
>>> but I digress...).
>>>
>>> When executed on the command line, this works perfectly. When I execute
>>> the same script via Apache and mod_php, I'm getting this exception:
>>>
>>> PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
>>> missing database in /home/mwolff/webs/markus/cms/test.php on line 8
>>>
>>> Getting experimental, I've tried to change the calls for the DELETE
>>> statements from $pdo->query() to $pdo->exec(), just to see what happens.
>>> Well, what happens is that I'm getting a different error:
>>>
>>> PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
>>> file in /home/mwolff/webs/markus/cms/test.php on line 6
>>>
>>> Argh... what can possibly be wrong here? The script works from the
>>> commandline, with the exact same PHP version (Debian package, PHP
>>> 5.2.0-8+etch7, and we also tried upgrading to the latest Debian package
>>> of 5.2.4, to no avail).
>>>
>>> It can't be file permissions, I've even tried to set the database file
>>> to 777... no change at all.
>>>
>>> Does this ring a bell with anyone here?
>>>
>>> Thanks,
>>> Markus
>>>
>>

--
Markus Wolff
-Development-

NorthClick GmbH

Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Internet: http://www.northclick.de/

Geschäftsführer: F. Detzner | M. Henze | C. Springub Amtsgericht Hamburg,
HRB 94459

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 03.10.2007 19:25:36 von Goltsios Theodore

--------------020006060308070603040601
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi again Markus,
This is realy confusing but since the command line execution works
for you then the problem should be php configuration for the mod_php. I
came up with this try to edit your php.ini and in case you use
pdo_sqlite extension then change the order of the loaded modules to this:

| extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so

You could also define the full path of the extensions like this:
||
extension_dir="/usr/local/include/php/ext/pdo/"

instead of this:

||extension_dir = "./"

In case your apache is compiled by hand and you have updated sqlite you
should recompile your apache against the new sqlite.

Hope this do some magic for you cause I have run out of ideas.

|

--
Thodoris



O/H Markus Wolff έγραψε:
> Hi Thodoris,
>
> I've checked on one of the three boxes now and the SQLite version used
> by both the commandline client and PDO is 3.2.8. I know the other two
> boxes have different versions, but I always created the database anew
> on each box.
>
> I also tried chown/chmod on the parent directory, no change.
>
> CU
> Markus
>
> Thodoris schrieb:
>> Hey Markus,
>> You should try to "chown apache:apache" and "chmod +w" to the
>> directory that includes frontend.db . And the link that I posted says:
>>
>> |/*
>> ** file_format==1 Version 3.0.0.
>> ** file_format==2 Version 3.1.3.
>> ** file_format==3 Version 3.1.4.
>> **
>> ** Version 3.0 can only use files with file_format==1. Version 3.1.3
>> ** can read and write files with file_format==1 or file_format==2.
>> ** Version 3.1.4 can read and write file formats 1, 2 and 3.
>> */
>>
>> Meaning that not all sqlite3 versions support all file formats. That
>> is why you should check the version of sqlite.
>> |
>>
>> --
>> Thodoris
>>
>>
>>
>>
>> O/H Markus Wolff έγραψε:
>>> Hey there,
>>>
>>> I've double-checked on three different machines now, and I'm always
>>> getting the same error. All having different versions of PHP,
>>> Apache, PDO and SQLite. So I figure it must be something that I'm
>>> doing wrong. I just can't figure out what it is - and I'm puzzled
>>> because I had used SQLite before (although briefly) and don't think
>>> I'm doing anything different than before.
>>>
>>> Anyway, here's what I'm doing, step-by-step:
>>>
>>> # sqlite3 frontend.db
>>>
>>> Here I insert the following SQL script:
>>>
>>> CREATE TABLE website (
>>> website_id INTEGER PRIMARY KEY,
>>> always_expand INTEGER
>>> );
>>>
>>> CREATE TABLE page (
>>> page_id INTEGER NOT NULL PRIMARY KEY,
>>> parent_id INTEGER,
>>> website_id INTEGER NOT NULL,
>>> title TEXT,
>>> link TEXT,
>>> depth INTEGER,
>>> visible INTEGER,
>>> element_id INTEGER,
>>> nav_path TEXT,
>>> protected INTEGER,
>>> sort_order INTEGER
>>> );
>>>
>>> Then I exit the client and make the PHP script:
>>>
>>> # nano test.php
>>>
>>> The content of the script still being that of my original message.
>>> Then I adjust the rights:
>>>
>>> # chown apache:apache frontend.db
>>> # chmod 777 frontend.db
>>>
>>> Then I execute the script on the command line:
>>>
>>> # php test.php
>>>
>>> No error.
>>>
>>> Then I call the script on the website, one of the examples being:
>>> http://www.21st.de/test.php
>>>
>>> The script still manages to open the database and do a SELECT query,
>>> but throws the said exception when trying to do the DELETE statement.
>>>
>>> These are all the steps that are involved to reproduce the error on
>>> three machines. No more, no less. Now, have I overlooked anything?
>>> Am I missing something really, really stupid? Or is it some kind of
>>> a bug? But certainly that could not have gone unnoticed for so long?
>>> (Tested on PHP versions 5.1.4, 5.2.0 and 5.2.4).
>>>
>>> CU
>>> Markus
>>>
>>> Markus Wolff - NorthClick schrieb:
>>>> Hey there,
>>>>
>>>> I'm trying to open an SQLite3 database from a PHP very simple PHP
>>>> script:
>>>>
>>>> $db = dirname(__FILE__).'/frontend.db';
>>>> $pdo = new PDO('sqlite:'.$db);
>>>> $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
>>>> $pdo->query("SELECT * FROM page LIMIT 1");
>>>> echo "Deleting pages\n"; $pdo->query("DELETE FROM page");
>>>> echo "Deleting websites\n";
>>>> $pdo->query("DELETE FROM website");
>>>>
>>>> The database file contains no data whatsoever, just the table
>>>> definitions (in case you were wondering, this is a stripped-down
>>>> version
>>>> of a larger script for debugging purposes, hence the seemingly idiotic
>>>> DELETE statements that won't do any good in an empty database anyway,
>>>> but I digress...).
>>>>
>>>> When executed on the command line, this works perfectly. When I
>>>> execute
>>>> the same script via Apache and mod_php, I'm getting this exception:
>>>>
>>>> PDOException: SQLSTATE[HY000]: General error: 1 SQL logic error or
>>>> missing database in /home/mwolff/webs/markus/cms/test.php on line 8
>>>>
>>>> Getting experimental, I've tried to change the calls for the DELETE
>>>> statements from $pdo->query() to $pdo->exec(), just to see what
>>>> happens.
>>>> Well, what happens is that I'm getting a different error:
>>>>
>>>> PDOException: SQLSTATE[HY000]: General error: 14 unable to open
>>>> database
>>>> file in /home/mwolff/webs/markus/cms/test.php on line 6
>>>>
>>>> Argh... what can possibly be wrong here? The script works from the
>>>> commandline, with the exact same PHP version (Debian package, PHP
>>>> 5.2.0-8+etch7, and we also tried upgrading to the latest Debian
>>>> package
>>>> of 5.2.4, to no avail).
>>>>
>>>> It can't be file permissions, I've even tried to set the database file
>>>> to 777... no change at all.
>>>>
>>>> Does this ring a bell with anyone here?
>>>>
>>>> Thanks,
>>>> Markus
>>>>
>>>
>


--------------020006060308070603040601--

Re: Can"t open SQLite DB... but only when using mod_php??

am 04.10.2007 02:53:45 von dmagick

Markus Wolff wrote:
> Chris schrieb:
>>> It can't be file permissions, I've even tried to set the database file
>>> to 777... no change at all.
>>
>> My guess is still permissions. If you try a raw fopen instead of using
>> pdo, what happens?
>>
>> >> error_reporting(E_ALL);
>> ini_set('display_errors', true);
>> $fp = fopen(dirname(__FILE__).'/frontend.db', 'r');
>> if ($fp) {
>> echo "Opened db
\n";
>> } else {
>> echo "Unable to open db
\n";
>> }
>> fclose($fp);
>> ?>
>
> Hey Chris,
>
> mmh wonder what could possibly be wrong when even trying 777? :-)

Some hosts check for and disable access to files that have wide-open
permissions - usually when php is running as a cgi but I've seen it when
using mod_php too.

If you try something other than 777 what happens? (644 just to see if
you can open it, then work on writing to it).

Can you see the file from this script?

$file = dirname(__FILE__) . '/frontend.db';
echo is_file($file) . '';

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 04.10.2007 10:50:12 von Markus Wolff - NorthClick

Am Donnerstag, den 04.10.2007, 10:53 +1000 schrieb Chris:
> > mmh wonder what could possibly be wrong when even trying 777? :-)
>
> Some hosts check for and disable access to files that have wide-open
> permissions - usually when php is running as a cgi but I've seen it when
> using mod_php too.

Hi Chris,

I've tried on a number of machines that have been setup either by me or
an admin I know. So I can say with some confidence that this is not the
case here :-)

> If you try something other than 777 what happens? (644 just to see if
> you can open it, then work on writing to it).

As one would expect, this yields a different exception because the
webserver can't open the database for write access anymore:

PDOException: SQLSTATE[HY000]: General error: 14 unable to open database
file in /home/mwolff/webs/markus/cms/test.php on line 6

> Can you see the file from this script?
>
> $file = dirname(__FILE__) . '/frontend.db';
> echo is_file($file) . '';

Yep.

CU
Markus

--
Mit freundlichen Grüßen
Markus Wolff
Development

NorthClick GmbH

Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Internet: http://www.northclick.de/

Geschäftsführer: F. Detzner | M. Henze | C. Springub
Amtsgericht Hamburg, HRB 94459

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Can"t open SQLite DB... but only when using mod_php??

am 04.10.2007 11:02:04 von Markus Wolff - NorthClick

Am Mittwoch, den 03.10.2007, 20:25 +0300 schrieb Thodoris:
> I came up with this try to edit your php.ini and in case you use
> pdo_sqlite extension then change the order of the loaded modules to
> this:
>
> extension=pdo.so
> extension=pdo_sqlite.so
> extension=sqlite.so

Still no change - and the CLI version of PHP was configured in the same
order as the mod_php version anyway, so there wouldn't be a difference.

> You could also define the full path of the extensions like this:
>
> extension_dir="/usr/local/include/php/ext/pdo/"

Actually, the full path seems to be some kind of hardcoded into the
build (at least that's the case with the Debian package of PHP I'm
currently working with), so no point in repeating that in the php.ini.

CU
Markus

--
Mit freundlichen Grüßen
Markus Wolff
Development

NorthClick GmbH

Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Internet: http://www.northclick.de/

Geschäftsführer: F. Detzner | M. Henze | C. Springub
Amtsgericht Hamburg, HRB 94459

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php