1

What is the difference between:

$db = new SQLiteDatabase('name.db');

and

$db = new PDO('sqlite:name.db');

Since, I don't understand the big picture here, details are premature for me and the information available online appears to assume certain knowledge I seem to be lacking. Please don't just paste in links to the PHP manual. Less specific, more general concepts will be useful for me.

Also, do both of these approaches use SQLite 3, as opposed to SQLite 2?

1 Answer 1

2

Directly using the SQLite functions/classes, your PHP code will only be compatible with SQLIte.

Using PDO, your PHP code will be compatible with many database systems -- see PDO Drivers for a list of existing drivers.
Quoting the Introduction page of PDO :

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data.


This abstraction layer can be useful if you want your code to be compatible with more than one DB engine ; but note that :
  • Using PDO, you cannot always use features that are specific to a database system
  • Using PDO means your PHP code will be compatible ; it doesn't mean your SQL will be too : that's still your job.

For the question about SQLite and SQLite3 :
  • PDO seems to support both -- see SQLite Functions (PDO_SQLITE)
    • To use one or the other, you should just have to use a different DSN.
    • Note : working with several distinct DB systems is the kind of thing for which PDO is great ;-)
  • Using the specific DB extensions :
    • There is one extension for SQLite2 : SQLite
    • And one other extension for SQLite3 : SQLite3
      • Note that this one seems to only be included with PHP >= 5.3
Sign up to request clarification or add additional context in comments.

4 Comments

Will both approaches make use of the same version of SQLite? Provided I am committed to SQLite, the non-PDO approach should exhibit better performance then, correct?
Not sure, about performances ;; I don't think there should be much of a difference, as the pdo_sqlite driver will probably just be a wrapper arround some system library to manipulate an SQLite DB, the same way the specific extensions are probably jsut wrappers arround that same manipulation stuff ;;; about using the same version of SQLite, as long as you are using (PDO/sqlite2 and SQLite), or (PDO/sqlite and SQLite3), I'd say it should
I'd never considered using PDO because the apps I would write I would never port to a new db, but reading your post makes me consider using PDO as a means to learn ONE API as the last one I'll need to learn (baring db specific feature requirements). Thanks.
YOu're welcome ; glad I could help :-) (this answer is quite a bit old, but I still don't regret having learnt using PDO -- I've used it with MySQL, SQL Server, Sqlite -- and in each case, having to know only one API is nice definitely ! )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.