1 year, 1 month ago
How can I retrieve the output of a stored procedure from a parametrized query using PHP/Mysqli?
I have a stored procedure that returns a single row. Simplified it looks like this:
CREATE PROCEDURE sp_headache (IN id INT)
BEGIN
DECLARE pid INT;
SELECT value INTO pid FROM users WHERE userID = id;
INSERT INTO anothertable (userpid) VALUES (pid);
SELECT pid;
END
When run in the MySQL environment, it returns one row with a single column,"pid". I am trying to call it from PHP as a parameterized query:
$mysqli = new mysqli($dbhost,$dbUser,$dbPass,$dbName);
$data->$mysqli->prepare("CALL sp_headache(?);");
$data->bind_param('i', $uid);
$data->execute();
$data->bind_result($a);
while ($data->fetch()) { $c = $a }
$data->close();
I get an error: Number of bind variables doesn't match number of fields in prepared statement
Anybody have any solutions?
Thanks in Advance!
CREATE PROCEDURE sp_headache (IN id INT)
BEGIN
DECLARE pid INT;
SELECT value INTO pid FROM users WHERE userID = id;
INSERT INTO anothertable (userpid) VALUES (pid);
SELECT pid;
END
When run in the MySQL environment, it returns one row with a single column,"pid". I am trying to call it from PHP as a parameterized query:
$mysqli = new mysqli($dbhost,$dbUser,$dbPass,$dbName);
$data->$mysqli->prepare("CALL sp_headache(?);");
$data->bind_param('i', $uid);
$data->execute();
$data->bind_result($a);
while ($data->fetch()) { $c = $a }
$data->close();
I get an error: Number of bind variables doesn't match number of fields in prepared statement
Anybody have any solutions?
Thanks in Advance!
Separate topics with commas, or by pressing return. Use the delete or backspace key to edit or remove existing topics.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$