PHPでSQLiteに書き込もうとしてGeneral error: 14 unable to open database file が出たときの対処

PHP5.2.5でPDOからSQLiteに普通にINSERTしようとしたとき、
Warning: SQLSTATE[HY000]: General error: 14 unable to open database file ...
とエラーが出て困った。SELECTは問題なくできる。

SQLiteのファイルのパーミッションが644だったりすると
Warning: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database
というエラーが出るのだが、666にしてあったのでこれではない。

結論としては、SQLiteのファイルを置いたディレクトリに書き込み権限が必要だった。(apacheの実行ユーザとかの)
下記のページを見て解決したのだが特にバグ、というわけでもないらしい。
[sqlite] Problems with SQLite and PHP
Re: [sqlite] Problems with SQLite and PHP

SQLite needs to be able to create and delete a journal file during
database modification.

マニュアルのコメントにも載っていた。
PHP: SQLite – Manual

いずれにせよ、unable to open database fileというのは不親切なエラーメッセージだと思う。

PHPのソースコードをちょっと追ってみた。
ext/pdo_sqlite/sqlite/src/os_unix.c
を書き換えればいいのかな?
実際にエラーが起きている箇所を特定できなかったが、sqlite3UnixOpenExclusive()だろうか。/var/tmp内にテンポラリファイルは開きそうなコードなのだがこのディレクトリは777でも関係なかった。sqlite3UnixTempFileName()にあるsqlite3_temp_directoryがなんなのかわからず。

This entry was posted in いじる. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

  1. By SanRin舎 » PHP on 2011/10/10 at 10:01 pm

    [...] [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Page optimized by WP Minify WordPress Plugin