I am intrigued to know why the return of values from a SP
using PDO
to connect to a MySql database does not work for me, I have read in the PHP documentation about PDO and I have replicated one of the examples and nothing else does not work for me. My PHP version 7.4.1
My test stored procedure is as follows:
DELIMITER #
CREATE PROCEDURE tomar(OUT cadena VARCHAR(20))
BEGIN
SET cadena = 'Hola Mundo';
END #
Now my code PHP
is as follows:
$connection = new PDO('mysql:host=localhost;dbname=shopic','root','');
$statement = $connection->prepare('CALL tomar(?);');
$statement->bindParam(1,$cadena,PDO::PARAM_STR,4000);
$statement->execute();
print "Devuelve: $cadena";
I am using XAMPP but I have also bought a hosting for tests, in none of them has it worked for me, it does not return anything. Also clarify that procedures that only have input parameters declared work perfectly for me. My doubt is they have changed something, has something new happened or what?
I have tried using a procedure that has a parameter IN OUT
and putting it in the method bindParam PDO::PARAM_STR|PDO::_PARAM_INPUT_OUTPUT
and it hasn't worked either.