jaypoc's Avatar
jaypoc 3
5 Asked
31 Answered
11 Best
0
No one has voted on this question yet :(
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!
Tip for best answer: M$4.00
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$

What is Your Answer?

0
0
0

Learn something new with our FREE educational apps!

Private lessons in the comfort of your own home. Get back in shape or finally pick up a guitar with our great experts guiding you the whole way!
Learn Guitar
Learn Hip Hop
Learn Pilates