Recently spent more than 10 days to re-write the kimchi blog, using the Php5+sqlite technology. The reason is that MySQL management is cumbersome, and it has to pay for a separate database.
SQLite is a lightweight, file-based embedded database, was born in 2000, after more than 7 years of development, until today has become the most popular embedded database, including Google, the company in its desktop software also uses SQLite to store user data. As you can see, there is no reason to doubt the stability of SQLite. (This section is from Lan Yu design)
So how do you use it in PHP5? There are 2 ways to connect to SQLite in PHP5. One is provided by default, and the other is the PDO class. The default only supports SQLITE2, but PDO can support sqlite3 indirectly. The following is a simple PDO class that I wrote to be compatible with 2 versions.
The following is the referenced content:
Class sqlite{
function __construct ($file) {
try{
$this->connection=new PDO (sqlite2:. $file);
}catch (Pdoexception $e) {
try{
$this->connection=new PDO (sqlite:. $file);
}catch (Pdoexception $e) {
Exit (error!);
}
}
}
function __destruct () {
$this->connection=null;
}
function Query ($SQL) {
return $this->connection->query ($SQL);
}
function Execute ($SQL) {
return $this->query ($SQL)->fetch ();
}
function Recordarray ($SQL) {
return $this->query ($SQL)->fetchall ();
}
function RecordCount ($SQL) {
Return count ($this->recordarray ($SQL));
}
function Recordlastid () {
return $this->connection->lastinsertid ();
}
}
The database is then instantiated and automatically created if the database exists in the instantiation, and does not exist.
The following is the referenced content:
$DB =new SQLite (blog.db); This database file name is arbitrary
Create a database table
The following is the referenced content:
$DB->query ("CREATE TABLE test (ID integer primary key,title varchar (50)");
Next Add the data
The following is the referenced content:
$DB->query ("INSERT INTO Test" values (kimchi));
$DB->query ("INSERT into test (title) VALUES (Blue Rain)");
$DB->query ("INSERT into Test (Ajan)");
$DB->query ("INSERT into test (title) VALUES (Proud snow blue sky)");
Then it's how to read the data. That is, loops.
The following is the referenced content:
$SQL =select title from Test order by id DESC;
foreach ($DB->query ($SQL) as $RS) {
echo $RS [title];
}
SQLite may be a little bit small for businesses, but it's a good thing for an individual, and portability is great.
My level is limited, if the above content is wrong please correct me. Thank you!
http://www.bkjia.com/PHPjc/486566.html www.bkjia.com true http://www.bkjia.com/PHPjc/486566.html techarticle recently spent more than 10 days to re-write the kimchi blog, using the Php5+sqlite technology. The reason is that MySQL management is cumbersome, and it has to pay for a separate database. SQLite is a lightweight 、...