Connect SQLite with PHP

For Connecting SQLite database with PHP, you must have PHP and SQLite installed on your system.

If sqlite is not installed, first install sqlite by using the following command:

Install Sqlite-php connection driver

Follow the steps given below systematically:

  • Create a folder "phpsqliteconnect" in www directory.
  • Create two subfolders "app" and "db" inside "phpsqliteconnect".
  • Create a JSON file "composer.json" inside "phpsqliteconnect", having the following code:

Open the Command prompt, go to the phpsqliteconnect and execute the following code:

SQLite Connect sqlite with php 1

Now, you will get the following message:

SQLite Connect sqlite with php 2

Note: The composer will create a new folder named "vendor" automatically.

if composer is not installed then first install composer

Now create a file name "index.php" in the root folder "phpsqliteconnect", having the following code:

The constant PATH_TO_SQLITE_FILE is used to store the path to the sqlite database file inside the db folder.

Now, create a new SQLiteConnection.php file and add the SQLiteConnection class as follows:

After having all classes in places, you use the following command to generate the autoload file:

SQLite Connect sqlite with php 3

Now, open the localhost an your browser http://localhost/phpsqliteconnect/

SQLite Connect sqlite with php 4

Connection is established successfully. You can also see the tree sturcture by by using the tree command:

SQLite Connect sqlite with php 5
Next TopicPython SQLite




Latest Courses