Php+sqlite Database Operations Example (create/Open/insert/retrieve), sqlite example _php tutorial

Source: Internet
Author: User
Tags sqlite database

Php+sqlite Database Operations Example (create/Open/insert/retrieve), sqlite example


This article describes the methods of Php+sqlite database operations. Share to everyone for your reference, as follows:

SQLite is a lightweight database, it is designed to be embedded, and has been used in many embedded products, it occupies a very low resource, in the embedded device, may only need hundreds of K of memory is enough. It can support Windows/linux/unix and so on mainstream operating system, and can be combined with many programming languages, such as Tcl, PHP, Java, and ODBC interface, also compared to MySQL, PostgreSQL, the two open source world-renowned database management system, is processing faster than they do.

PHP 5 is no longer the default support for MySQL, but the default support SQLite, it can be seen how much influence, so if you want to do sqlite PHP development, it is recommended that you use PHP 5.0.0 or later.

Here is an example of using SQLite

You can start by creating a new upload.db empty file in the directory.

<?phpdefine ("LN", __line__);//Line number define ("FL", __file__);//Current file define ("Debug", 0);//debug Switch $db_name = "upload.db";// Create the database file with the empty if (!file_exists ($db _name)) {if (! $fp = fopen ($db _name, "w+")) {exit (Error_code ( -1, LN)),} fclose ($FP);} Open the database file if (! ( $db = Sqlite_open ($db _name))) {exit (Error_code ( -2, LN));} Generate the data table structure if (!sqlite_query ($db, "DROP TABLE uploads")) {exit (Error_code ( -3, LN));}  if (!sqlite_query ($db, "CREATE TABLE uploads (ID integer primary key, file_name varchar () UNIQUE, make_time integer)") {Exit (Error_code ( -3, LN));} Insert a data if (!sqlite_query ($db, "insert into uploads (file_name, make_time) VALUES (' Upload/111.data ', '". Time (). ")") {Exit (Error_code ( -4, LN));} Retrieve the data out if (!) ( $result = Sqlite_query ($db, "select * from uploads")) {exit (Error_code ( -5, LN));} Gets the retrieved data and displays the while ($array = Sqlite_fetch_array ($result)) {echo "ID:". $array [file_name]. "
: ". $array [Make_time];} /* Error message code function */function Error_code ($code, $line _num, $debug =debug) {if ($code <-6 | | $code >-1) {return false;} SWITC H ($code) {case-1: $errmsg = "Create database file error."; Break Case-2: $errmsg = "Open SQLite database file failed."; Break Case-3: $errmsg = "Create table failed, table already exist."; Break Case-4: $errmsg = "Insert data failed."; Break Case-5: $errmsg = "Query database data failed."; Break Case-6: $errmsg = "Fetch data failed."; Break Case-7: $errmsg = ""; Break Default: $errmsg = "Unknown error."; } $m = "[Error]
File: ". BaseName (FL). "
Line: ". LN. "
MESG: ". $errmsg. ""; if (! $debug) {($m = $errmsg);} return $m;}? >

More interested in PHP related content readers can view this site topic: "PHP based on PDO operation database Tips Summary", "PHP+MONGODB Database operation Skills Daquan", "PHP Object-oriented Programming tutorial", "PHP String Usage Summary", " Php+mysql database Operation Tutorial "and" PHP common database Operation Skills Summary "

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1133080.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133080.html techarticle Php+sqlite Database Operations Example (create/Open/insert/retrieve), sqlite example This article describes the methods of Php+sqlite database operations. Share to everyone for your reference, as follows: ...

  • 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.