PEAR::SQLite: The Lightweight Alternative - Connecting to a Database
(Page 3 of 6 )
Connection to an SQLite database is a bit different if you've only worked with MySQL. MySQL is designed for a multi-user environment whereas SQLite was designed to be embedded in standalone applications. Consequently, you won't need a user ID and password to connect.
Instead you'll use an array to form a data source name (DSN). A DSN is essentially a pointer used to locate the database files.
The first key of the array is "database" and accepts the location of a file that will act as your database's information store. If the file doesn't exist, SQLite will attempt to create it and assign it the access permissions set by the next key, "mode".
The DSN is then passed to the connect method and a connection is established.
<?php $DSN = array( "database" => getcwd() . "/dbase/mydbase.db", "mode" => 0644); $db->connect($DSN); ?> |
The disconnect method is used to disconnect from the database.
<?php $db->disconnect(); ?> |
Next: Queries >>
More Database Articles Articles
More By bluephoenix