Hi All,
I am new to perl ,I am stuck with below issues....
I am querying to database to fetch a field for a user through a subroutine. Check the below code..
+..
1. if user is found in Database then subroutine returns the result. The print statement after the s
+oubroutine call print the result. (expected)
2. but if user is not found or the the column vlaue is empty for that user , then my program is ge
+tting terminated before return the result to the subroutine ....so the print statement after the
+subroutine call is not being exceuted...
Please help me...
Here is the code
#!/usr/bin/perl
use DBI;
$database = "idm";
$username = "idm";
$password = "idm";
$hostname = "localhost";
$output = &connectCBMS(900010); --> calling a subroutine
print $output; -- printing the result
sub connectCBMS {
$db = DBI->connect("DBI:Oracle:host=$hostname;sid=$database",$username,$password);
unless($db) {
#LogResult("(ERROR) Failed to connect to $DIRHOST.");
#ReportFailure("(ERROR) Failed to connect to $DIRHOST.");
print "(ERROR) Failed to connect to $hostname.";
return 0;
}
my ($staffcode) = @_;
# Execute a Query
my $sql = qq{ SELECT REGISTRATIONDAY FROM CBMS WHERE STAFFCODE = ? };
my $sth = $db->prepare( $sql );
$sth->bind_param( 1, $staffcode );
$sth->execute();
my $row;
while ( $row = $sth->fetchrow_array( ) ) {
return $row;
}
$sth->finish();
$db->disconnect();
exit(0);
}
Thanks
Suriya