Data Source Names
When connecting to a database via the DBI, you need to tell the DBI where to find the database to connect to. For example, the database driver might require a database name, or a physical machine name upon which the database resides. This information is termed a data source name, and of all the aspects of DBI, this is possibly the most difficult to standardize due to the sheer number and diversity of connection syntaxes.
The DBI requires the data source name to start with the characters
dbi:, much like a URL begins with
http:, and then the name of the driver, followed
by another colon—for example, dbi:Oracle:.
Any text that follows is passed to the driver’s own
connect()
method to interpret as it sees fit. Most drivers expect either a
simple database name or, more often, a set of one or more
name/value pairs separated with
semicolons. Some common examples are listed later in this section.
For example, mSQL requires the hostname, database name, and potentially, the TCP/IP port number for connecting to the database server. However, Oracle may require only a single word that is an alias to a more complicated connection identifier that is stored in separate Oracle configuration files.
DBI offers two useful methods for querying which data sources are available to you for each driver you have installed on your system.
Firstly, you can get a list of all the available drivers installed on
your machine by using the
DBI->available_drivers()
method. This returns a list ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access