PHP: Hot Pages: SQLite: Other database servers

  1. Manage your data
  2. SQLite

We used PHP’s “PHP Data Objects” method of accessing the database, so everything should work the same in other databases that also use PDO. PHP’s PDO system is designed to make your database code portable. If you transfer your database from SQLite to another database server, you should be able to make it work by changing only one line, the line where you create the database object.

For example, if you’re using a MySQL server on mysql.example.com, you might change:

$database = new PDO('sqlite:/home/ACCOUNT/databases/poll.sqlite3')

to be something like:

$database = new PDO('mysql:host=mysql.example.com;dbname=poll', 'user', 'password');

Where in SQLite you create a database object by giving it the path to the database file, in most other database servers you’ll create a database object by giving it the hostname of the database server, the name of the database on that server, a user name for accessing that database, and a password for that user name.

  1. Manage your data
  2. SQLite