Trying to get a simple PHP/Zend Framework setup to create a SQLite databse and manipulate it.
<?php
require_once("Zend/Db.php"); // Zend framework
$db = Zend_Db::factory('Pdo_Sqlite', array("dbname" => "./test.sqlite3"));
$sql = "CREATE TABLE IF NOT EXISTS ".$db->quoteIdentifier("configs")." (".$db->quoteIdentifier("name")." TEXT NOT NULL PRIMARY KEY, ".$db->quoteIdentifier("value")." TEXT NOT NULL);";
echo $sql;
$db->query($sql);
The SQL echoes out as “CREATE TABLE IF NOT EXISTS "configs" ("name" TEXT NOT NULL PRIMARY KEY, "value" TEXT NOT NULL);“, which looks right.
But I get a ‘Zend_Db_Statement_Exception‘ with message ‘SQLSTATE[HY000]: General error: 14 unable to open database file’. I’ve tried taking off the leading “./” on the “dbname” variable, and ensured that the folder the PHP file is in has write permissions for everyone. I even tried creating the file with “touch test.sqlite3” and ensured it was writable by everyone.
This is using PHP v5.2.10
your code is working here (on windows). so the
array("dbname" => "./test.sqlite3")syntax is not the problem. as others, i assume it’s a permission issue.some ideas:
straceyour script (strace php test.php) and check the output for permission errors../test.sqlite3is to be created must be readable and writable by the user running php. it is not enough to have a readable and writabletest.sqlite3, because sqlite also reads and writes a temporarytest.sqlite3-journalfile in this directory. make sure it is.pdoandpdo_sqliteextensions are loaded (check the output ofphpinfo()). also, see that are no conflicts between the system and the php bundled sqlite libs.