SQLite Introduction
SQLite is a lightweight database, is to comply with acid's relational database management system, its design goal is embedded, and has been used in many embedded products, it occupies very low resources, in embedded devices, may only need hundreds of K of memory is enough.
It can support Windows/linux/unix and so on mainstream operating system, simultaneously can with many programming language combination, for instance tcl, PHP, Java, C + +,. NET, as well as ODBC interface, but also compared to Mysql, PostgreSQL these two open source world famous database management system, it processing faster than they.
A single PHP connection sqlite the table and uses the INSERT and SELECT statements to manipulate the SQLite database.
Before using SQLite, we want to make sure that SQLite and PDO configurations are enabled in PHP.ini
Open the php.ini file and lay the following extensions:
Copy Code code as follows:
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 emits a SELECT statement.
Loops and displays the results.
Unable to open a temporary database file for storing temporary tables
Unable to open the temporary database file that stores the temporary table, in the Windows environment, if the above error occurs,
Use Putenv ("Tmp=c:/temp"), and specify a temporary folder.
See the code specifically:
<?php
//Temp directory in the Windows environment, use PUTENV ("Tmp=c:/temp") If this error occurs, and specify a temporary folder.
//putenv ("tmp=c:/temp");
Open
the database if ($db = Sqlite_open ("Test.db", 0666, $sqliteerror)) {
//CREATE TABLE
sqlite_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);
The SELECT statement
$sql = "SELECT * from user order BY id desc LIMIT";
Execute SQL statement
$res = Sqlite_unbuffered_query ($db, $sql);
Display results while
($item = Sqlite_fetch_array ($res, Sqlite_assoc)) {
print ID:. $item [id]. " Name: ". $item [' name '];
print "<BR>";
Close Database
sqlite_close ($DB);
} else {
print $sqliteerror;
}
? >
Php+sqlite database operation Tutorial and example
<?php
//Set script maximum execution time
set_time_limit (0);
SQLite database filename
$db _name = ' md5.db ';
Open the SQLite database
$db = Sqlite_open ($db _name);
Exception handling
if (! $db) {
echo Cannot connect SQLite file: ', $db _name, ' <br/> ';
} else{
Echo ' successfully connected SQLite file: ', $db _name, ' <br/> ';
}
Create data table: MD5 password table
sqlite_query ($db, "CREATE TABLE MD5 (s int (4) PRIMARY key,d varchar ())");
Insert record
$s = 0;
while ($s <= 999999) {
$d = MD5 ($s);
Sqlite_query ($db, "INSERT into MD5 VALUES ($s, ' {$d} ')");
$s + +;
}
Retrieves 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 SQLite connection
sqlite_close ($db);
? >
PHP Read SQLite starter version
<?php
//Open SQLite database
//$db = @sqlite_open ("Mm.sqlite", 0666, $error);//No support
//$db = new PDO (' SQLite: Mm.sqlite ');
Exception handling
if (! $db) die ("Connection Sqlite failed.\n");
Add a database
//@sqlite_query called foo ($db, "CREATE TABLE foo (bar varchar)");
Insert a record
//@sqlite_query ($DB, insert into foo VALUES (' Fnord '));
Retrieves all records
$result = $db->query (' Select Bottleencryptusrname from BottleTable4 ');
Print fetched Results
foreach ($result as $row) {
echo $row [0];
echo "<br>";
>