28

Trying to learn a bit about PDO and is going through this tutorial. It has the following snippet of code:

<?php

  try
  {
    $db = new PDO('sqlite::memory');
    echo "SQLite created in memory.";
  }
  catch(PDOException $e)
  {
    echo $e->getMessage();
  }

When I run this I get the following exception message:

SQLSTATE[HY000] [14] unable to open database file

What does that mean? How can I get it to work? I am able to connect to a MySQL database and also a regular SQLite database file. So I know at least something is working...

I'm on Windows 7 64-bit with Apache 2.2.11 and PHP 5.3.0 (latest WampServer install). phpinfo() reports that I have pdo_sqlite with SQLite Library 3.6.15 enabled.

4

2 に答える 2

52

あなたは書く必要があります

$db = new PDO('sqlite::memory:');

末尾:がありません。


PDO_SQLITE データ ソース名 (DSN) は、次の要素で構成されます。

DSN プレフィックスはsqlite:です。

  • ディスク上のデータベースにアクセスするには、DSN プレフィックスに絶対パスを追加します。

  • メモリ内にデータベースを作成するには、DSN プレフィックスに:memory:を追加します。

ドキュメンテーション

于 2010-03-11T14:30:25.753 に答える
2

@ win パーミッションは不明ですが、* nix では、SQLite は一時ファイル用のデータベース ファイルを限定するディレクトリへの書き込みパーミッションが必要です。

于 2010-03-11T14:13:14.727 に答える