DB::connect()

DB::connect() -- Connects to a database

Synopsis

object DB::connect (mixed $dsn [, array $options = array()])

Description

Creates a new DB connection object and connect to the specified database

Parameter

string or array $dsn

Data Source Name. String formats are described in the DSN section while array formats are covered in the Introduction - Connect section.

array $options

An optional argument can contain runtime configuration settings for this package. See setOption() for more information on the available settings.

Return value

object - the created DB connection object. DB_Error object on failure.

Throws

Table 21-1. Possible PEAR_Error values

Error codeError messageReasonSolution
DB_ERROR_NOT_FOUND NULL The database specific class was not found. Check the $dsn and make sure to have an complete installation of the DB-package and that you database is supported by DB.

Note

This function should be called statically.

See

DB::disconnect(), Tutorial - Connect