Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Integrating PHP with Databases Querying the Database with PHP Querying the Database

What is the database.db File?

Hello, i know how to use the normal "non Objective" connection:

$servername = 'localhost';
$username = '123';
$password = '456';
$database = 'mydb';
$conn = new mysqli($servername, $username, $password, $database);

But i don't see any data that i need to insert into the PHP file to connect them both together. That's bit confusing.

1 Answer

Spenser Hale
Spenser Hale
20,914 Points

Hey Damian,

The database.db is the SQLite Database file. It contains all the information of the SQLite Database, including database and table schemas, and their corresponding data.

You can access the SQLite Database by using PHP PDO, which abstracts away having to code each query to the specific database extension you want to use.

<?php

try {
  $db = new PDO("sqlite:".__DIR__."/database.db");
  $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
  echo "Unable to connect";
  echo $e->getMessage();
  exit;
}