Im using SQLite and PDO in PHP for the first time.
I wrote simple connect procedure:
try
{
$link = new PDO("sqlite:".$file);
$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
echo 'SQLite error: ' . $e->getMessage();
}
I moved my database file, to test error handling and… new database was created.
I don’t want new database, i want error! What should I do?
Temporarily i wrote if with file_exists() condition, but maybe there is better way?
No, there isn’t. This behaviour is by design and covers (I guess ;)) 99% of all use-cases, because in a common setup the database is created only once and doesn’t just move. This said:
file_exists()is the way to go 🙂 And it’s not bad, so why looking for a better way?