| DESY HOME | IT HOME | Print Preview | Print Window |
If the needed driver is missing, contact the UCO or your system administator.
Below you will find a sample file which you may run to connect to the ORACLE database
instance DESY.
In this sample script are two important handles.
The first one $dbh is the database handle which handles the connection.
The second $sth is the statement handle, it actually encapsulates individual SQL statements to be executed within the database.
If the operating system is UNIX, don't forget to
set the environment.
If the operating system is WINDOWS several network components have to be installed,
some dynamic load libraries (dll) must be available and environment settings have to be done.
Simply install
SQL/ODBC by using NETINSTALL and all needed dlls are on your computer and the needed environment settings are done.
To check the environment and applications based on ORACLE using SQL*PLUS will be helpfull.
Copy this sample file to sample.pl and run it. The result will be a listing of the
employee number and name which is stored in the table emp of the test account
scott.
This script can be used to execute other queries. Simply insert your account and
password into $dbuser, $pass, change the table name from emp to your table name
and insert the column names.
If WINDOWS is your operating system, call the DOS command prompt and execute
perl sample.pl
#!/opt/products/bin//perl
# This path may be different, it is platform dependent.
#
use DBI;
#---------------------------------------------------------------------------
#-- change user name, password, table name, column names
#---------------------------------------------------------------------------
$dbname = 'dbi:Oracle:desy';
$dbuser = 'scott';
$pass = 'tiger';
$table = 'emp';
$columns = 'empno,ename';
#
#---------------------------------------------------------------------------
#
# connect to the database
$dbh = DBI->connect($dbname, $dbuser, $pass) or die "Cant connect to : $DBI::errstr\n";
# select entries in the database
$sth = $dbh->prepare(qq{select $columns from $table});
# execute the select statement
$sth->execute;
while (@row = $sth->fetchrow_array)
{
print "@row\n";
}
# end the reading of results
$sth->finish;
# disconnect from the database
$dbh->disconnect;
# that's all
exit;
Imprint
© 2010
Last update: 07. Feb. 2006
www-it@desy.de