首页 > 解决方案 > Calling this stored procedure in php

问题描述

excuse me, can you please suggest me how can I call this stored procedure (https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=cdeacd70bac986d28e9a6e5cb84774c2) in php? I'd like to have those four numbers in four variables, so I can display those data on my webpage. I'm sure that I'm not understanding something. That's the code I'm using but it does not works (I get always 0):

$conn = new PDO("mysql:host=$servername;dbname=dbcbt", $username, $password);


$sql = 'CALL CountMacro_Audit_Scaduti(?,?,?,?); select @CountMacro1, @CountMacro2, @CountMacro3, @CountMacro4';
$stmt = $conn->prepare($sql);

$CountMacro1 = 0;
$CountMacro2 = 0;
$CountMacro3 = 0;
$CountMacro4 = 0; 

$stmt->bindParam(1, $CountMacro1, PDO::PARAM_INT, 10);
$stmt->bindParam(2, $CountMacro2, PDO::PARAM_INT, 10);
$stmt->bindParam(3, $CountMacro3, PDO::PARAM_INT, 10);
$stmt->bindParam(4, $CountMacro4, PDO::PARAM_INT, 10);

print "Values of bound parameters _before_ CALL:\n";
print "  1: {$CountMacro1} 2: {$CountMacro2} 3: {$CountMacro3} 4: {$CountMacro4}\n";

$stmt->execute();

print "Values of bound parameters _after_ CALL:\n";
print "  1: {$CountMacro1} 2: {$CountMacro2} 3: {$CountMacro3} 4: {$CountMacro4}\n";


标签: phpmysqlstored-procedurespdo

解决方案


推荐阅读