Skip to content
Advertisement

Using pdo in php with stored procedure

I have a simple stored procedure in MySQL database:

JavaScript

When calling this procedure in mysql-workbench it returns the data I put in:

Screenshot form mysql work bench

Now when I call it from PHP using pdo I get an error:

JavaScript

Here is my php code:

JavaScript

Advertisement

Answer

You need to use bindValue instead of bindParam.

When you use bindParam, it binds the variable provided to the parameter, not the value of the variable.

So, if you do:

JavaScript

It’s actually executed with 6 rather than 5. To do this, the method must have a reference to the variable. You cannot have a reference to a literal, so this means that bindParam cannot be used with literals (or anything you can’t have a reference to).

JavaScript

Then:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement