Please help with Perl script to fetch stored procedure from MySQL database. The following Perl Code Snippet is supposed to fetch 2 result sets in accordance with the result of the following MySQL stored procedure execution.
Is there a "next()" method for DBI fetchrow() viz.,
while(my $row = $sth->fetchrow()) {
say($row);
$sth->fetchrow(next);
}
Perl:
use feature ':5.22';
use strict;
use warnings;
use DBI;
my $dsn = "DBI:mysql:procdb";
my $username = "root";
my $password = '';
my $dbh = DBI->connect($dsn, $username, $password);
die "failed to connect to MySQL database:DBI->errstr()" unless($dbh);
say "Connected to MySQL Server successfully.";
my $sth = $dbh->prepare("CALL prepend('abcdefg', \@inOutParam);") or die "prepare statement failed: $dbh->errstr()";
$sth->execute() or die "execution failed: $dbh->errstr()";
$sth->dump_results();
$sth->finish();
$dbh->disconnect();
Perl Output:
Connected to MySQL Server successfully.
'abcdefg'
1 rows
0 rows
MySQL:
DROP DATABASE IF EXISTS procdb;
DELIMITER $$
CREATE DATABASE procdb;$$
DELIMITER ;
USE procdb;
DROP PROCEDURE IF EXISTS prepend;
DELIMITER $$
CREATE PROCEDURE prepend
(
IN inParam VARCHAR(255),
INOUT inOutParam INT
)
BEGIN
DECLARE z INT;
SET z = inOutParam + 1;
SET inOutParam = z;
SELECT inParam;
SELECT CONCAT('zyxw', inParam);
END;$$
DELIMITER ;
USE procdb;
CALL prepend('abcdefg', @inOutParam);
MySQL Output:
abcdefg
zyxwabcdefg
Thanks