Php file database SQLite

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff. What is SQLite? Before entering the code, let's make sure you have a clear understanding of what SQLite is (and not. Unlike MySQL, MySQL runs in the client-server mode, while SQLite is a file-based database engine.

Welcome to the Linux community forum and interact with the 2 million technical staff> what is SQLite? Before entering the code, let's make sure you have a clear understanding of what SQLite is (and not. Unlike MySQL, MySQL runs in the client-server mode, while SQLite is a file-based database engine.

Welcome to the Linux community forum and interact with 2 million technicians>

What is SQLite?

Before entering the code, let's make sure you have a clear understanding of what SQLite is (and not. Unlike MySQL, MySQL runs in client-server mode, while SQLite is a file-based database engine that uses file I/O (input/output) function to store and read files from the disk. It is much smaller than MySQL (the SQLite command line version is smaller than KB) and supports most of the familiar SQL commands.

This small size should not fool you, but according to the official SQLite Web site, SQLite supports a database that grows to GB in size and is actually faster than MySQL in some cases. SQLite database files are easy to carry, and SQLite databases created on the Windows platform work well on the * NIX platform, and vice versa.

One of the most attractive aspects of SQLite is that it is completely non-typed. Fields in the SQLite database do not need to be associated with specific types, and even if they are associated, you can still insert different types of values into these fields (this is an exception, but I will talk about it later ). This is important because it means that if you are concerned about entering the wrong type value into your table, you need to write code in your application to implement type check.

Another important difference between MySQL and SQLite is their licensing policy: Unlike MySQL, SQLite source code is completely public, this means that you can choose to use and distribute it in both commercial and non-commercial products.

To use SQLite and PHP together, your PHP must contain SQLite. By default, this function works in the UNIX and Windows versions of PHP5.

However, if you are a PHP 4. users of Version x can still use SQLite by manually downloading and installing the php_sqlite.dll file or the latest tar package. you don't need to download anything else; SQLite's 'client' is its own engine.

SQL commands

Like MySQL, you can use common SQL commands to exchange functions with SQLite databases. The exact SQL syntax used by SQLite is listed above, but for most operations, SQL commands are standard.

The following is an example of creating a table that I will use in this tutorial:

C: \ WINDOWS \ Desktop \ sqlite> sqlite library.

Db SQLite version 2.8.15 Enter ". help" for instructions sqlite>

Create table books

(

...>

Id integer primary key,...>

Title varchar (255) not null,...>

Author varchar (255) not null…> );

Sqlite> insert into books

(Title, author)

Values

(The Lord Of The Rings, 'J. R. R. Tolkien ');

Sqlite> insert into books

(Title, author)

Values

('The Murders In The Rue morge', 'edgar Allen Poe ');

Sqlite> insert into books

(Title, author)

Values

('Three Men In A boat', 'jerome K. Jerome ');

Sqlite> insert into books

(Title, author)

Values

('A Study In Scarlet', 'Arthur Conan Doyle ');

Sqlite> insert into books

(Title, author)

Values

('Alice In Wonderland', 'Lewis carroll ');

Sqlite>. exit

You can use the SQLite command line program to enter the preceding commands interactively or non-interactively. The SQLite command line program can be obtained through compiled binary files on Windows and Linux platforms. SQLite 2. * is the version currently used in two PHP branches, and SQLite 3. * It is expected to support PDO and PHP5. * later versions.

Decompress the downloaded file to a directory of your choice. In your shell or DOS window, run the cd command to enter the Directory and enter 'sqlite '. you can see the SQLite version information and the following line:

Enter ". help" for instructions

Once the data is input to the database file library. db, run the SELECT query immediately to check whether everything works well:

Sqlite> select * from books;

1 | The Lord Of The Rings | J. r. r. tolkien 2 | The Murders In The Rue Morgue | Edgar Allen Poe 3 | Three Men In A Boat | Jerome K. jerome 4 | A Study In Scarlet | Arthur Conan Doyle 5 | Alice In Wonderland | Lewis Carroll

If you see the same result as the above output, you are ready to start.

[1] [2] [3] [4]

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.