: This article mainly introduces how to use SQLCipher to compile sqlite3 for php in CentOS to support database encryption. if you are interested in PHP tutorials, refer to it. Recently, due to project requirements, sqlite generated on the server must be encrypted. the server uses php to write data in the background, and the operating system is CentOS. open-source sqlite3 reserved database encryption interfaces, but not implemented. so I found SQLCipher on the Internet, which implements the unimplemented encryption function of sqlite3 and supports sqlite database encryption by re-compiling the sqlite3 extension of PHP.
Specific operation, can refer to the steps of the official website, address: https://www.zetetic.net/sqlcipher/sqlcipher-for-php/
On the official website, the system uses Ubuntu. here, you can convert the corresponding commands to those used in CentOS. refer to the Operation steps on the official website to compile the program successfully,
After the compilation is successful, sqlite3.so will be generated and replaced directly with sqlite3.so in the previous php extension server (it is best to make a backup before replacement). after the replacement is complete, restart the apache server,
To test the code:
// Create a test. sqlite file with a password of 12345678. Parameter 6 indicates that the file will be opened if there is one. if not, create the file. for details, refer to sqlite3.c in the source file.
$ Db = new Sqlite3 ("test. sqlite", 6, "12345678 ");
$ Db-> exec ("create table mytest (name varchar (200 ))");
$ Db-> exec ("insert into mytest (name) values ('aaa ')");
$ Result = $ db-> query ('select * FROM mytest ');
Print_f ($ result );
?>
If the result can be printed, it indicates that sqlite3 has been re-compiled successfully. this is basically a success, but you still need to check whether the generated database is encrypted. the generated test. sqlite can be opened with some of its own tools. generally, an error is prompted. this indicates that sqlite has been successfully encrypted.
By the way, the official website also provides support for android and IOS, which can be viewed on the official website.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above section describes how to use SQLCipher to compile sqlite3 for php in CentOS to support database encryption, including some content. I hope to help my friends who are interested in PHP tutorials.