MySQL Tutorial/Procedure Function/Perl — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 13:44, 26 мая 2010
Calling a stored procedure in Perl
$dbh = DBI->connect("DBI:mysql:$database:$host:$port","$user", "$password",{ PrintError => 0}) || die $DBI::errstr;
if ($dbh->do("call error_test_proc(1)"))
{
printf("Stored procedure execution succeeded\n");
}
else
{
printf("Error executing stored procedure: MySQL error %d (SQLSTATE %s)\n %s\n",
$dbh->err,$dbh->state,$dbh->errstr);
}
Get returning value from a MySQL stored procedure in Perl
$stmt=$my_db->prepare("SELECT isodd(?)") or die($my_db->error);
$stmt->bind_param("i",$aNumber) or die($stmt->error);
$stmt->execute() or die($stmt->error);
$stmt->bind_result($isodd);
$stmt->fetch();
if ($isodd == 1 )
printf("%d is an odd number\n",$aNumber);
else
printf("%d is an even number\n",$aNumber);