in reply to Re^3: Calling MySQL stored procedures with in and out parameters
in thread Calling MySQL stored procedures with in and out parameters

I know the code is error.
But I don't know how to call the MySQL procedure that have a INOUT parameter. Such as :
CREATE PROCEDURE `TEST_COUNT_PLUS`(INOUT NUMBER1 INTEGER)

If one INOUT parameter change to one IN parameter and one OUT parameter, such as :
CREATE PROCEDURE `TEST_COUNT_PLUS_2`(IN NUMBER2 INTEGER, OUT NUMBER3 I +NTEGER)

The skill of the answer is OK. So, I think if set the parameter NUMBER1 value before call procedure, it may work. But skill is Very poor.

Replies are listed 'Best First'.
Re^5: Calling MySQL stored procedures with in and out parameters
by morning_leaf (Initiate) on Apr 06, 2015 at 15:39 UTC
    It's my mistake. change the " to ', then OK. Now the follow code can be run :
    #!/usr/bin/perl # # PROCEDURE `TEST_COUNT_PLUS` # # CREATE DEFINER=`root`@`localhost` PROCEDURE `TEST_COUNT_PLUS`(INOUT +NUMBER1 INTEGER) # BEGIN # DECLARE NUMBER2 INTEGER # DEFAULT (SELECT COUNT(*) FROM PLAYERS); # SET NUMBER1 = NUMBER2 + NUMBER1; # END$$ use strict; use DBI; my @hit_count; my $dbh = DBI->connect('dbi:mysql:tennis','BOOKSQL','BOOKSQLPW') or di +e "Connection Error: $DBI::errstr\n"; $dbh->do('set @hit_count=10'); # change " to ', disable interpreter. my $sql = 'call TEST_COUNT_PLUS(@hit_count)'; my $sth = $dbh->prepare($sql); $sth->execute || die $DBI::errstr; $sth->finish; # Now get the output variable my @result = $dbh->selectrow_array('SELECT @hit_count') || die $DBI::e +rrstr; print "result=", $result[0], "\n"; $dbh->disconnect;