Can't open database file PDO Sqlite in the same directory

PDOException show that:

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

Just a line of, tried every option, works with absolute path only, but project will be moved on server, what to do?

enter image description here

Upvotes: 1

Views: 2154

Answers (1)

apokryfos
apokryfos

Reputation: 40653

If the DB file is in the same directory as the php script you can use

$dbo = new PDO("sqlite:".__DIR__.DIRECTORY_SEPARATOR."links.db");

The __DIR__ magic constant will always have the absolute path of the currently running script which may be different than the current working directory. Overall it's good practice to use absolute paths.

Upvotes: 3

Related Questions