0

I can use MySQL stored procedures with one parameter but when I try and use multiple parameters the stored procedure doesn't seam to be called. I will paste the php code I have then the SQL code. Can anyone give any indication why it's not working?

Thanks

<?php 

//DB Connection include
include '/connection/proccon.php';    

 $skill=1;
 $level=1;
 $user=1;

//SQL for identify user 
$sqlquestion = sprintf("call updatequestion('%s, %s, %s')", $skill, $user, $level);

echo $sqlquestion;
$resultquestion = mysqli_query($link, $sqlquestion);    

?>

SQL Below

--Procedure: updatequestion

--DROP PROCEDURE IF EXISTS updatequestion;

DELIMITER |

CREATE DEFINER = 'root'@'%' PROCEDURE updatequestion 
(
  IN  v_uid    int,
  IN  v_level  int,
  IN  v_qid    int
)
BEGIN
INSERT INTO answer (qid,uid,level) VALUES(v_qid,v_uid,v_level);
END|

DELIMITER ;
1
  • You put quotes around all the parameters, so it's just one string instead of 3 separate parameters. Commented Jul 9, 2014 at 8:56

2 Answers 2

1

Use the quotes better, you included 3 parameters into 2 quotes, that's wrong, i think.

Solution:

**

$sqlquestion = sprintf("call updatequestion(%s, %s, %s)", $skill, $user, $level);

**

Have a nice day

Sign up to request clarification or add additional context in comments.

Comments

0

Change it to:

$sqlquestion = sprintf("call updatequestion(%s, %s, %s)", $skill, $user, $level);

The quotes were combining all the parameters into one string.

2 Comments

Thank you, spent ages on this there is very little online with this notation.
There are examples of procedures with multiple parameters here: mysqltutorial.org/stored-procedures-parameters.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.