Example of how php reads the sqlite database, and how to operate the sqlite getting started instance in php programming.
Reference: http://www.jbxue.com/article/php/22383.html
Before using SQLite, make sure that the sqlite and pdo configurations are enabled in php. ini.
Open the PHP. ini file and perform the following extensions:
Extension = php_pdo.dll
Extension = php_pdo_sqlite.dll
Extension = php_sqlite.dll
The sqlite_open command is used to open a database file.
If no file exists, it is created.
Sqlite_query can execute SQL statements.
Create a table and insert data.
Sqlite_unbuffered_query issues a SELECT statement.
Loop and display results.
Unable to open a temporary database file for storing temporary tables
The temporary database file storing temporary tables cannot be opened. In Windows, if the above error occurs,
Use putenv ("TMP = C:/temp"); to specify a Temporary Folder.
For details, see the code:
<? Php // The temporary directory is in Windows. If the preceding error occurs, use putenv ("TMP = C:/temp") to specify the Temporary Folder. // Putenv ("TMP = C:/temp"); // open the database www. jbxue. comif ($ db = sqlite_open ("test. db ", 0666, $ sqliteerror) {// create a table sqlite_query ($ db," create table user (id integer primary key, name text );"); // INSERT statement $ SQL = "insert into user values (NULL, 'name')"; // execute the SQL statement $ res = sqlite_query ($ db, $ SQL ); // SELECT statement $ SQL = "select * from user order by id desc limit 20"; // execute the SQL statement $ res = sqlite_unbuffered_query ($ db, $ SQL ); // display the result while ($ Item = sqlite_fetch_array ($ res, SQLITE_ASSOC) {print "ID :". $ item ["id"]. "NAME :". $ item ["name"]; print "<BR>" ;}; // close the database sqlite_close ($ db) ;}else {print $ sqliteerror ;}?>
PHP + SQLite database operation tutorial and example
<? Php // set the maximum execution time of the script set_time_limit (0); // sqlite database file name $ db_name = 'md5. db'; // open the sqlite database $ db = sqlite_open ($ db_name); // Exception Handling if (! $ Db) {echo 'cannot connect to the SQlite file:', $ db_name, '<br/>';} else {echo 'successfully connects to the SQlite file:', $ db_name, '<br/>';} // CREATE a data TABLE: MD5 password TABLE sqlite_query ($ db, "create table md5 (s int (4) primary key, d varchar (32 )) "); // insert record $ s = 0; while ($ s <= 999999) {$ d = md5 ($ s); sqlite_query ($ db, "insert into md5 VALUES ($ s, '{$ d}')"); $ s ++;} // retrieve all records $ result = sqlite_query ($ db, 'select * FROM md5'); echo '<pre>'; while ($ row = sqlite_fetch_array ($ result, SQLITE_BOTH) {echo 'md5: ', $ row ['d], 'src:', $ row ['s '],' <br/> ';} echo '</pre>'; // close the SQLite connection sqlite_close ($ db);?>
Php read sqlite entry Edition
<? Php // open the sqlite database // $ db = @ sqlite_open ("MM. sqlite ", 0666, $ error); // not supported // $ db = new PDO ('sqlite: MM. sqlite '); // Exception Handling if (! $ Db) die ("Connection Sqlite failed. \ n "); // Add a database named foo // @ sqlite_query ($ db," create table foo (bar varchar (10 ))"); // INSERT a record // @ sqlite_query ($ db, "insert into foo VALUES ('fnord ')"); // retrieve all records $ result = $ db-> query ('select BottleEncryptUsrName from bottletable4'); // print the obtained result foreach ($ result as $ row) {echo $ row [0]; echo "<br>" ;}?>