$db_handle
= DBI->connect(data_source, user, passwd, [\%attr])
- Connects to the specified database, returning a database handle object. The
connect
method automatically installs the driver if it has not already been installed.
- data_source
- A string identifying the driver to connect to, and any other additional driver-specific information needed to identify the driver (e.g., a port number.) The driver name is written in the form
dbi:
driver_name
, e.g., dbi:mSQL
. (Default value is taken from the DBI_DSN environment variable.) For example, a connection string for the mSQL driver always starts with dbi:mSQL:
. The second colon should be followed by any information required by the driver to make the database connection. In the case of mSQL, you must supply a database name (tutorialdb
in the following example), a hostname (localhost
), and the port number of the database server (1114
):
dbi:mSQL:tutorialdb:localhost:1114
- user
- The user name for the database connection. (Default value is taken from the DBI_USER environment variable.)
- passwd
- The password for the database connection. (Default value is taken from the DBI_PASS environment variable. Set this value at your own risk.)
- \%attr
- A hash reference defining attributes for the database handle.