I am playing around with DBD::mysql (MySQL v5.6) and perl, experimenting with stored procedures and functions, which I've never used before. I see that there is the ability to make an OUT parameter to the procedure. How do I access that from perl?
I have it working in MySQL:
DELIMITER // DROP PROCEDURE IF EXISTS DebugMe // CREATE PROCEDURE DebugMe(OUT arg char(10)) BEGIN SET arg = "HELLO"; END // DELIMITER ; CALL DebugMe(@blah); SELECT @blah; Query OK, 0 rows affected (0.00 sec) +-------+ | @blah | +-------+ | HELLO | +-------+ 1 row in set (0.00 sec)
But not in perl:
use warnings; use strict; use DBI; my $dsn = 'DBI:mysql:database=test'; my $dbh = DBI->connect($dsn, @ARGV, {RaiseError => 1}); my $sth = $dbh->prepare('SELECT "Hello World"'); $sth->execute(); printf "SELECT rows = %d\n", scalar $sth->rows; printf "\t(@$_)\n" for $sth->fetchrow_arrayref; my $v; $sth = $dbh->prepare('CALL DebugMe(?)'); $sth->execute($v); $sth->execute(\$v); __END__ SELECT rows = 1 (Hello World) DBD::mysql::st execute failed: OUT or INOUT argument 1 for routine tes +t.DebugMe is not a variable or NEW pseudo-variable in BEFORE trigger +at sscce.pl line 14. DBD::mysql::st execute failed: OUT or INOUT argument 1 for routine tes +t.DebugMe is not a variable or NEW pseudo-variable in BEFORE trigger +at sscce.pl line 14.
Is this possible? Or will I have to use other methods (like a stored function return-value, or a procedure with multiple result sets)?
In reply to How to access MySQL stored procedures OUT parameter(s) by pryrt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |