In CentOS, php uses SQLCipher to compile sqlite3 and supports database encryption.

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.