Generally, you open a single connection to a database and then perform all the required operations through it by executing a sequence of SQL statements. To open a connection, you use the connect method. The return value is a handle to the database connection that you use to perform subsequent operations on that connection.
The parameters to the connect method are as follows:
The following code sample opens and closes a connection to the SQL Anywhere sample database. You must start the database server and sample database before running this script.
#!/usr/local/bin/perl -w # use DBI; use strict; my $database = "demo"; my $data_src = "DBI:SQLAnywhere:ENG=$database;DBN=$database"; my $uid = "DBA"; my $pwd = "sql"; my %defaults = ( AutoCommit => 1, # Autocommit enabled. PrintError => 0 # Errors not automatically printed. ); my $dbh = DBI->connect($data_src, $uid, $pwd, \%defaults) or die "Cannot connect to $data_src: $DBI::errstr\n"; $dbh->disconnect; exit(0); __END__ |
Optionally, you can append the user name or password value to the data-source string instead of supplying them as separate parameters. If you do so, supply a blank string for the corresponding argument. For example, in the above script may be altered by replacing the statement that opens the connections with these statements:
$data_src .= ";UID=$uid"; $data_src .= ";PWD=$pwd"; my $dbh = DBI->connect($data_src, '', '', \%defaults) or die "Can't connect to $data_source: $DBI::errstr\n"; |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |