开发者

PHP with Zend Framework can't start a SQLite database?

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 开发者_如何学GoNULL 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:

  • if you are running the program with php as apache module: does it work if run from the command line? what are the permissions of the file created? adjust the permissions to the apache user accordingly.
  • if above does not work: strace your script (strace php test.php) and check the output for permission errors.
  • the directory where ./test.sqlite3 is to be created must be readable and writable by the user running php. it is not enough to have a readable and writable test.sqlite3, because sqlite also reads and writes a temporary test.sqlite3-journal file in this directory. make sure it is.
  • try using an absolute path for the database name.
  • make sure the pdo and pdo_sqlite extensions are loaded (check the output of phpinfo()). also, see that are no conflicts between the system and the php bundled sqlite libs.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜