Subject: Problem when calling stored procedure 2007-11-04 - By Pierre Hainard
Back Hello I try to read a stored procedure p1 from a table listproc in database test _texte and use it after giving a value to her parameters in an other database.
#/usr/bin/perl
use strict; use warnings; use DBI;
my @(protected); my $user = 'papa';my $password = 'pa3418'; my $para1;my $para2;
my $dbh_1 = DBI->connect ("dbi:mysql:test_texte",$user,$password, {RaiseError => 1, PrintError => 1}) or die "can't connect ($DBI::errstr)\n";
my $sth_1 = $dbh_1->prepare("SELECT Liste FROM listeproc"); $sth_1->execute; my $cont = 0; while ($linproc[$cont] = $sth_1->fetchrow_array ) { $cont++; } print "linproc[0] is : $linproc[0]"; $dbh_1->disconnect;
my $dbh = DBI->connect ("dbi:mysql:test",$user,$password, {RaiseError => 1, PrintError => 1}) or die "can't connect ($DBI::errstr)\n";
# # Calling the procedure $para1 = 10;$para2 = 12; my $procedure = "CALL p1($para1,$para2)";
#this one does work my $sth = $dbh->prepare($procedure); #this one does not work why ?? #my $sth = $dbh->prepare({$linproc[0]}); $sth->execute();
my $more_results; my $count = 0; do { $count++; print "\ndonnees $count\n"; my $names = $sth->{NAME}; print_line($names); print_line([map {'-' x length $_} @$names]); my $rows = $sth->fetchall_arrayref(); print_line ($_) for @$rows; } while ( $more_results = $sth->more_results);
$dbh->disconnect;
sub print_line { my ($line) = @(protected); print q{ }, join(q{ }, map {sprintf '%-12s', $_} @$line),"\n"; }
sleep(20);
Meilleures salutations
Pierre Hainard Chalet 15 CH-2300 La Chaux de Fonds p.hainard@(protected)
|
|