connect

connect is used to create a connection to a data source. Here is an example of a simple connect statement:

$db_handle = DBI->connect($datasource, $user, $password)      or die ("Error: $DBI::errstr\n");

A hash of attributes can also be passed:

$db_handle = DBI->connect($datasource, $user, $password, \%attr)      or die ("Error: $DBI::errstr\n"); 

If there is an error connecting, $DBI::errstr will be set, and the call will die with the message we include in the die call.

The $datasource string can be quite complex. For MySQL, it is commonly something like this:

DBI:mysql:PerlBook

where mysql is the DBD and PerlBook is the database name. If the data source happens to be on another server, then the data source needs to contain a bit more information.

DBI:mysql:PerlBook@database.perlguy.net:989

In this case, we specify the URL of the server where the database hosts. Also, we specify the port (989) that the database server listens on.



Perl Database Programming
Perl Database Programming
ISBN: 0764549561
EAN: 2147483647
Year: 2001
Pages: 175

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net