Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

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;
}