Php uses pdo to connect to sqlite3, pdosqlite3. Php uses pdo to connect to sqlite3. pdosqlite3 this article describes how to configure php to connect to sqlite3 using pdo. For your reference, the configuration example of connecting php to sqlite3 using pdo is as follows: pdosqlite3
This example describes how to configure php to connect to sqlite3 using pdo. We will share this with you for your reference. The details are as follows:
When I first started using php + sqlite, I always thought I was using sqlite3. actually, it wasn't. php started to support sqlite3 by default only when php5> = 5.3.0.
See the official document http://www.php.net/manual/zh/sqlite3.open.php
Default method interface:
Public void SQLite3: open (string $ filename [, int $ flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE [, string $ encryption_key])
When using PHP to operate the database, it is found that PHP only supports Sqlite2 by default, and does not support the latest version of Sqlite3. To support Sqlite3, use PDO. To use PDO, you need to load the php_pdo.dll and php_pdo_sqlite.dll modules in php. ini. As follows:
extension=php_pdo.dllextension=php_pdo_sqlite.dll
If pdo is not used, even if you open the above parameter, you still use sqlite2. if you do not believe it, check whether the generated database prompts at the beginning of the file:
** This file contains an SQLite 2.1 database **
The following error is reported when the above supported configuration is not enabled in the php environment:
Fatal error: Call to undefined function sqlite_open ()
Sqlite3 example:
<? Php // $ dsn = 'sqlite: SQL. db'; try {// $ dbh = new PDO ($ dsn, $ user, $ password); // create a connection // $ dbh = new PDO ('sqlite: yourdatabase. db'); $ dbh = new PDO ('sqlite: itlife365.com '); echo 'create db OK '; // CREATE a TABLE $ dbh-> exec ("Create Table itlife365 (id integer, name varchar (255)"); echo 'create TABLE itlife365 OK
'; $ Dbh-> exec ("insert into itlife365 values (1, 'itlife365. com')"); echo 'Insert Data OK
'; $ Dbh-> beginTransaction (); $…… = $ dbh-> prepare ('select * FROM itlife365'); $……-> execute (); // get the result $ result = $ TH-> fetchAll (); print_r ($ result); $ dsn = null;} catch (PDOException $ e) {echo 'connection failed: '. $ e-> getMessage (); $ dsn = null;}?><? Php $ dbh = null; // or use unset ($ dbh);?>
Verify: view the database:
Display in the file header:
SQLite format 3 ***
More clearly can refer to the official website: http://cn.php.net/manual/zh/ref.pdo-sqlite.php