Use of PHP and sqlite Databases

Source: Internet
Author: User
I 've been using PHPmysql all the time. Today, I tried sqlite. From configuring sqlite to using php for connection tests, I found a lot of related resources on the Internet. Due to version changes, there are different opinions, it takes a lot of time. Php5.5.9 is used this time. The following section describes how to configure and use sqlite as a reference. 1. Configure sqlite ::

I 've been using PHPmysql all the time. Today, I tried sqlite. From configuring sqlite to using php for connection tests, I found a lot of related resources on the Internet. Due to version changes, there are different opinions, it takes a lot of time. Php5.5.9 is used this time. The following section describes how to configure and use sqlite as a reference. 1. Configure sqlite ::

I have been using PHP + mysql all the time. Today, I tried sqlite. From configuring sqlite to using php for connection tests, I found a lot of related resources on the Internet. Due to version changes, there are different opinions, it takes a lot of time. Php5.5.9 is used this time. The following section describes how to configure and use sqlite:

1. Configure sqlite:

: Http://www.sqlite.org/download.html

I use win7 64-bit, so I need to download these two files:

Sqlite-shell-win32-x86-3080500.zip

Sqlite-dll-win64-x64-3080500.zip

Decompress the package to obtain the following files: sqlite3.dll 、sqlite3.def?sqlite3.exe

Put the three Files in the same directory, for example, E: \ Program Files (x86) \ sqlite,

Run the CMD command prompt cd to enter the sqlite folder, and only use the command:

Sqlite3 DBName. db

To create a database named DBName,


Use the create Statement on the command line to create a data table.




The following is the source code for successfully connecting to and outputting the database:

The official connection document is used as a correct reference.

Http://www.php.net/manual/zh/class.sqlite3.php


//./Address is the database directory
$ Db = new PDO ('sqlite:./address/test. db ');
$ Db-> beginTransaction ();
// Company is the name of the data table.
$ Something = $ db-> prepare ('select * FROM company ');
$ Something-> execute ();
$ Result = $ something-> fetchAll ();
Echo"

"; 

Print_r ($ result );
?>

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.