sqlite correct path/URI for php pdo on windows sqlite correct path/URI for php pdo on windows sqlite sqlite

sqlite correct path/URI for php pdo on windows


The solution

Notice the simple slash in the DSN sqlite:/ ? Just drop it !

write your DSN like this :

sqlite:name.db.

This works with relative and absolute paths so :

$dsn = 'sqlite:c:\full\path\to\name.db'; // --WORKS--

$dsn = 'sqlite:..\data\name.db'; // --WORKS--

$dsn = 'sqlite:name.db'; // --WORKS--

Hope it will save you some time in the future !


Just a small append to @justin answer:

You can also use the linux path style on windows:

$dsn = 'sqlite:c:/full/path/to/name.db';


Better than PDO('sqlite:...') is to use PHP sqlite3 extension and its SQLite3 class. I have tried your advices above with a database on an external (hard)drive and it didn't work (still giving the same error as mentioned in the first post by @justin-t). Then I tried with SQLite3 class and... Hurray! It worked!

(Just for those who are wondering about PDO and a lot of its weird bugs.)