Tuesday, June 2, 2009

Test Perl connect Oracle

#!/usr/bin/perl

$oracle_server="";
$oracle_listener="";
$oracle_sid="";
$oracle_port="1521";
$oracle_user="";
$oracle_password="";
$oracle_table_de_test="dual";

use DBI;
use DBD::Oracle;

my $dbh = DBI->connect("dbi:Oracle:host=$oracle_server;port=$oracle_port;sid=$oracle_sid",$oracle_user, $oracle_password)
or die "khong the ket noi den database : " . DBI->errstr;

my $sth = $dbh->prepare("SELECT * FROM $oracle_table_de_test")
or die "prepare khong the thuc thi " . $dbh->errstr;

$sth->execute()
or die "khong the thuc thi cau sql: " . $sth->errstr;

while ( my @data = $sth->fetchrow_array() )
{
my $firstname = $data[1];
print "\t: $firstname \n";
}

if ($sth->rows == 0)
{
print "Table vide\n";
}

$sth->finish;

$dbh->disconnect;

No comments: