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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.