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
I also tried chown/chmod on the parent directory, no change.
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.
O/H Markus Wolff έγραψε:
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,
CREATE TABLE page (
page_id INTEGER NOT NULL PRIMARY KEY,
website_id INTEGER NOT NULL,
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
Then I call the script on the website, one of the examples being:
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).
Markus Wolff - NorthClick schrieb:
I'm trying to open an SQLite3 database from a PHP very simple PHP
$db = dirname(__FILE__).'/frontend.db';
$pdo = new PDO('sqlite:'.$db);
$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?
Gasstr. 10 - 22761 Hamburg
Tel.: 040 8 22 44 999 - Fax: 040 8 22 44 998
Geschäftsführer: F. Detzner | M. Henze | C. Springub Amtsgericht Hamburg,
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php