0

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";


ADyson
  • 57,178
  • 14
  • 51
  • 63
  • it would be a lot more sensible if the procedure just returned a result set instead of 4 individual output parameters. Anyway in the PHP version you shouldn't need the `SELECT`, you should just be able to bind to the output parameters directly. – ADyson Feb 10 '20 at 11:22
  • I added the Select to see if it works, but using just: "CALL CountMacro_Audit_Scaduti(?,?,?,?)" does not works in the same way :(. I need to have 24 result divided in 6 procedures. I cant do 24 procedures. – Domenico Schitti Feb 10 '20 at 11:31
  • It appears there is a longstanding bug which means this doesn't work very well. https://stackoverflow.com/questions/13382922/calling-stored-procedure-with-out-parameter-using-pdo . Like I said, just return a resultset from the procedure (via a SELECT) instead of output parameters. P.S. I have no idea what the 24 procedures problem is...your comment doesn't make any sense based on everything else you've said. – ADyson Feb 10 '20 at 11:41
  • the 24 proc. thing was just to say that I cant split this procedure in more procedure, one for every result (it's not related to the question so forget it xD). What does "longstanding bug" means? – Domenico Schitti Feb 10 '20 at 11:54
  • it means a bug (in PDO) which has been there for a long time – ADyson Feb 10 '20 at 12:03

0 Answers0