2

I use Sqlcipher in PHP. I want to select data from the encrypted database. I can select and decrypt data in command line by blow sqlite command:

$ sqlite3 test.db
sqlite> pragma key='secret';

Below php code execute perfectly with sqlit3 databse but not with sqlcipher encrypted database:

$con = new SQLite3('test.db');
$con->query("SELECT * FROM people;")->fetchArray();

How can I use pragma key='secret'; in SQL query in PHP?

Hossein
  • 3,755
  • 2
  • 29
  • 39
  • Executing SQLite 'pragma' from PHP: [526310/with-sqlite-how-do-you-show-current-pragma-settings](https://stackoverflow.com/questions/4526310/with-sqlite-how-do-you-show-current-pragma-settings). SQLCipher and the 'secret' pragma is mentioned here: [/groups.google.com/forum](https://groups.google.com/forum/#!topic/sqlcipher/gBxq3sApUXc) – Ryan Vincent Dec 13 '14 at 15:28

1 Answers1

1

We need to build SQLCipher into the SQLite extension used within PHP.

$con = new SQLite3("test.db"); 
$con->exec("PRAGMA key = 'secret';"); 
$con->query("SELECT * FROM people;")->fetchArray();
Hossein
  • 3,755
  • 2
  • 29
  • 39