Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why PHP PDO SQLite always creates a new empty database file?

Tags:

php

sqlite

pdo

I created connection to database, but I dont know why it always create a new empty database.sql file. When I rename the database file he creates always a new file instead giving me an error.

Here is my code

$db = new PDO("sqlite:".__DIR__."/database.sql");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
like image 883
Denis Milosavljevic Avatar asked Jul 23 '26 16:07

Denis Milosavljevic


1 Answers

This is the expected behaviour. When SQLite is called, it looks for the filename specified.

    $db = new PDO("sqlite:".__DIR__."/database.sql");

If the database.sql file is not found, it will attempt to create the file.

As an aside, you might want to change the file extension from .sql to .sqlite for clarity.

like image 101
Kevin Waterson Avatar answered Jul 25 '26 06:07

Kevin Waterson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!