lerner1225
lerner1225

Reputation: 902

sqlite3 PDO error

I am trying to open an encrypted sqlite3 database using PDO (PHP 7.1.1).

$db = new PDO('sqlite:mydb.sqlite','','password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$results = $db->query('SELECT * from Table');

The above code throws following exception:

Uncaught PDOException: SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database

Is my connection string correct? Is it possible to open an encrypted sqlite3 database using PDO?

Upvotes: 2

Views: 1022

Answers (1)

Josiah Hudson
Josiah Hudson

Reputation: 1005

The documentation for the PDO SQLite interface makes no mention of encryption, nor does the documentation for the PDO class. The only thing I'm aware of is the SQLite3 class which has a parameter for an encryption key in the constructor.

Per the documentation:

encryption_key - An optional encryption key used when encrypting and decrypting an SQLite database. If the SQLite encryption module is not installed, this parameter will have no effect.

As mentioned in the comments on your question, there are other answers which address installing and getting a sqlite encryption module working with PHP.

Upvotes: 1

Related Questions