PHP cannot connect to sqlite3 Solution

Source: Internet
Author: User
Currently, PHP does not support sqlite3, that is, it does not support SQLite database files with the db3 suffix. when using PHP to connect to sqlite3, an error is reported. The following is a solution: [copy reference materials] the following content is reference content:
 
If you get an error message:Warning: sqlite_open() [function.sqlite-open]: file is encrypted or is not a databasethen most probably your code is accessing a SQLite3 database.sqlite_open() only supports SQLite2. Use PDO to access SQLite3.
The solution is to use PDO to connect to sqlite3. here we also recall what PDO and ADODB are. both PDO and ADODB are database abstraction layers. the general function is to connect to multiple databases, which is especially suitable for implementing multiple databases in one program. PDO supports database migration. If you deploy multiple databases in the future, use it. at the same time, PDO is designed for C and has a high execution efficiency. it has been encapsulated as an extension library component of PHP. it runs fast and has high efficiency. To sum it up, we need to be more secure. It can prevent SQL injection and be a beginner. I don't know if there is any error. ADODB is a PHP class and a PHP file. Compared with PDO, it has a low running efficiency, but is also widely supported and easy to use. it is said that ADODB also supports SQLite. However, ADODB is also based on PHP components, so it certainly does not support sqlite3, so PDO is the only solution to this problem. here, it means that sqlite3 has been around for four years. What have you done with PhP5? Then write down the PDO and the connection method between PDO and SQLite: pDO: http://pecl.php.net/package/pdoPDO_Sqlite function and Syntax: CompileExtension = php_pdo.dllextension = php_pdo_sqlite.dllAfter PDO and pdo_dqlite are enabled, I started to write a test code, copied a task database to the program directory for testing. [Copy references] the following content is reference content:
 
<?$dbh = new PDO('sqlite:spiderresult.db');if ($dbh){echo 'OK';}else{echo 'Err';}foreach ($dbh->query('SELECT id FROM content limit 10;') as $row){echo "$row[0]";}?>

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.