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?
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$fp = fopen(dirname(__FILE__).'/frontend.db', 'r');
if ($fp) {
echo "Opened db<br/>\n";
} else {
echo "Unable to open db<br/>\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