Database Reference
In-Depth Information
DBI connect Syntax
The DBI call for establishing a database session is connect . It has the following syntax:
$dbh = DBI->connect($data_source, $username, $auth, \%attr);
In Perl, names of scalar variables are prefixed by $ , and hashes by % (please run perldoc
perlintro for an explanation of the terms scalar and hash). Table 22-3 explains the parameters
of the connect call.
Table 22-3. connect Parameters
Parameter
Meaning
$dbh
Database handle for the database session.
$data_source
Data source, i.e., specification for connecting to a local ORACLE instance
or contacting a listener. The following formats are supported:
"DBI:Oracle:" , "DBI:Oracle:<Net service name>" ,
"DBI:Oracle:host=<host_name>;port=<port_number>;sid=<ORACLE_SID>" ,
"DBI:Oracle:<host_name>:<port_number>/<instance_service_name>" , 5
or undef .
$username
Database username, “/” for OS authentication, or undef .
$auth
Password or undef .
\%attr
Optional reference to a hash with connect options.
The Perl keyword undef represents an undefined value analogous to NULL in SQL. If one of
$data_source , $username , or $auth are undef , then environment variables are used, if available.
Table 22-4 lists the parameters and the corresponding environment variables. 5
Table 22-4. Perl DBI Environment Variables
Parameter
Environment Variable
$data_source
DBI_DSN
$username
DBI_USER
$auth
DBI_PASS
The value of $data_source must always start with the string “DBI:Oracle:”. Note that the
uppercase “O” in the string “Oracle” as well as the colon (:) after the string “Oracle” are manda-
tory. Using a lowercase “o” causes the following error:
DBD::oracle initialisation failed: Can't locate object method "driver" via package
"DBD::oracle"
5. The Oracle Net easy connect format is available in Oracle10g and subsequent releases.
 
Search WWH ::




Custom Search