in reply to How to access MySQL stored procedures OUT parameter(s)

Hello again pryt,

I hope you still follow our thread. I found some time and decide to look into it a bit more. Regarding the part you said # thanos1983's links suggested a two-step process: can be done in one step also to minimize the resources. You can use the do method. In your case it can be used without the prepare execute step.

From the documentation:

This method is typically most useful for non-SELECT statements that ei +ther cannot be prepared in advance (due to a limitation of the driver +) or do not need to be executed repeatedly. It should not be used for + SELECT statements because it does not return a statement handle (so +you can't fetch any data).

Having said that, here is a sample that replicates your test, based on your final post:

#!/usr/bin/perl use strict; use warnings; use Test::More; use DBI qw/:sql_types/; my $dsn = 'DBI:mysql:database=DB'; my $dbh = DBI->connect($dsn, 'user', 'psw', {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 $rows = $dbh->do('CALL DebugMe(@dmvar)') or die $dbh->errstr; my ($v) = $dbh->selectrow_array('SELECT @dmvar'); is( $dbh->errstr , undef , 'SELECT(@dmvar) without error' ); is( $v , 'HELLO' , 'DebugMe(@dmvar); SELECT @dmvar' ); done_testing(); $sth->finish; __END__ $ perl mysql.pl SELECT rows = 1 (Hello World) ok 1 - SELECT(@dmvar) without error ok 2 - DebugMe(@dmvar); SELECT @dmvar 1..2

The idea came from the MySQL forums HOW TO RETRIEVE AN "OUT" PARAMETER OF MYSQL STORED PROCEDURE IN PERL. I remembered the user mentioned that is working, worth it to give it a try.

Relevant question Multiple data sets in MySQL stored procedures,in case of future reference(s).

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: How to access MySQL stored procedures OUT parameter(s)
by pryrt (Abbot) on Sep 01, 2017 at 23:38 UTC

    Ah, yes, by "two step", I meant step#1:CALL DebugMe(@dmvar), step#2:SELECT(@dmvar). But I do appreciate the reminder of $dbh->do(). As you might be able to tell, I'm not actually a database guy. :-)

    As far as the Multiple-data-sets, that was actually something I had run across in the documentation, and was probably going to experiment with... but $work got in the way of my coffee-break perl/mysql experimentation. :-)

    In the end, I'll probably just switch to a stored function instead of stored procedure, because (so far), I only have one value I want returned. (I had been thinking about a second, but it hasn't materialized yet, and probably won't.)

    Thanks for staying interested.