3
I want to connect to a database that already exists using PDO and sqlite in PHP, and here is the code I have:
class Database extends PDO{
public function __construct(){
parent::__construct("sqlite: userquestion.db");
$this->exec("PRAGMA foreign_keys = ON;"); // enable foreign keys
}
}
However, when I instate this class, it creates a new file userquestion.db
, instead of simply opening connection to the existing file.
PS: I have checked and I am using the name and directory correctly.
Is he writing over the existing one? Is there a version compatibility problem? The documentation says something about this. http://php.net/manual/en/ref.pdo-sqlite.php. I doubt this is a problem, but does the whitespace before the name affect anything? In the documentation he picks up the
realpath("userquestion.db")
before using the file name, is that not it? You say that the directory is correct. Are you sure?– Maniero
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero