PHP read the introduction to SQLite database instance

Source: Internet
Author: User
Tags md5 php programming sqlite database

PHP Read the example of the SQLite database, PHP programming to operate the SQLite starter instance.
Original 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 a php.ini file and lay the following extensions:
Extension=php_pdo.dll

Extension=php_pdo_sqlite.dll
Extension=php_sqlite.dll
The Sqlite_open command is to open a database file.
If no files are created.

Sqlite_query can execute SQL statements.
Create a table and insert data.

Sqlite_unbuffered_query issues a SELECT statement.
Loops and displays the results.

Unable to open a temporary database file for storing temporary tables
You cannot open a temporary database file that stores temporary tables, in a Windows environment, if the above error occurs,
Please use putenv ("Tmp=c:/temp") and specify a temporary folder.

For details, see the code:

<?PHP//temporary directory in a Windows environment, if the above error occurs, use Putenv ("Tmp=c:/temp") and specify a temporary folder. Putenv ("tmp=c:/temp");//Open Database www.jbxue.comif($db=Sqlite_open("Test.db", 0666,$sqliteerror)) {//Create a tableSqlite_query($db, "CREATE table user (ID integer primary key,name text);");//INSERT Statement$sql= "INSERT into user values (NULL, ' name ')";//Execute SQL statement$res=Sqlite_query($db,$sql);//SELECT statement$sql= "SELECT * from user order BY id desc limit 20";//Execute SQL statement$res=Sqlite_unbuffered_query($db,$sql);//Show Results while($item=Sqlite_fetch_array($res,Sqlite_assoc)) {Print"ID:".$item["id"]. " NAME: ".$item["Name"];Print"<BR>";};//Close the databaseSqlite_close($db);} Else {Print $sqliteerror;}?>

Php+sqlite Database operation Tutorials and examples

<?PHP//set the maximum execution time for a scriptSet_time_limit(0);//SQLite database file name$db _name= ' Md5.db ';//Open SQLite Database$db=Sqlite_open($db _name);//Exception Handlingif( !$db ) {Echo' Cannot connect to SQLite file: ',$db _name, ' <br/> ';}Else{Echo' Successfully connected to SQLite file: ',$db _name, ' <br/> ';}//Create data table: MD5 password TableSqlite_query($db, "CREATE TABLE MD5 (s int (4) PRIMARY key,d varchar (32))");//Inserting Records$s= 0; while($s<= 999999){$d=MD5($s);Sqlite_query($db, "INSERT into MD5 VALUES ($s,‘{$d}‘)");$s++;}//Retrieving 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> ';//Turn off SQLite connectionSqlite_close($db);?>

PHP Read the starter version of SQLite

<?PHP//Open SQLite database//$db = @sqlite_open ("Mm.sqlite", 0666, $error);//not supported//$db = new PDO (' sqlite:MM.sqlite ');//Exception handlingif(!$db) die("Connection Sqlite failed.\n");//add a database called 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 results obtainedforeach($result  as $row){Echo $row[0];Echo"<br>";}?>
Related Article

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.