0

I've read all around, there is no clear answer what is the difference between:

$db = new SQLite3('/directory/file.db');
$db = new SQLite('/directory/file.db');
$db = new PDO('sqlite:/directory/file.sqlite');

from what I can tell there is no difference between the bottom two? I'm trying to use the best solution for PDO with sqlite3

thanks.

2 Answers2

0

Basically, those are 3 different extensions for handling databases.

SQLite version 3 has changed so much, it needed new driver. So SQLite3 library was created.

SQLite is when you want to use SQLite databases older than version 3.

PDO is library, that allows you changing of Database driver without touching your code.

Basically, when using PDO you don't write SQL queries, but create query objects. Those generate query dependent on currently selected database. Allowing you to smoothly change database.

http://www.php.net/manual/en/book.pdo.php

http://www.php.net/manual/en/book.sqlite.php

http://www.php.net/manual/en/book.sqlite3.php

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Grzegorz
  • 3,538
  • 4
  • 29
  • 47
0
$db = new SQLite3('/directory/file.db');

That's the SQLite3 extension, see here: http://php.net/SQLite3.

$db = new PDO('sqlite:/directory/file.sqlite');

That's the PDO extension with the sqlite driver, also for SQLite3 databases. See http://php.net/manual/en/ref.pdo-sqlite.php.

If you like PDO's interface, this is nice. Otherwise, SQLite3 is fine too. See https://stackoverflow.com/a/10703665/476 for what the difference between PDO and other extensions are.

$db = new SQLite('/directory/file.db');

This is:

In PHP 5.1, the SQLite extension also provides a driver for SQLite 2 databases; while it is not technically a part of the PDO_SQLITE driver, it behaves similarly, so it is documented alongside it. The SQLite 2 driver for PDO is provided primarily to make it easier to import legacy SQLite 2 database files into an application that uses the faster, more efficient SQLite 3 driver. As a result, the SQLite 2 driver is not as feature-rich as the SQLite 3 driver.

Community
  • 1
  • 1
deceze
  • 510,633
  • 85
  • 743
  • 889