I’ve been reading up on Stored Procedures & MYSQLi from here http://php.net/manual/en/mysqli.quickstart.stored-procedures.php
and other sources, but am still unsure how to call a stored procedure with ? (like a prepared statement)
Is it possible to bind parameters to a stored procedure, in something similiar to this:
$mysqli->query("CREATE PROCEDURE p(IN id_var INT) BEGIN INSERT INTO test(id)
VALUES(id_var); END;"))
$mysqli->bindParam("i", $some_int);
$mysqli->query("CALL p");
Binding parameters is a PHP-side operation; stored procedures are a MySQL thing. The two are not related and should not be treated as such.
With prepared statements and parameter-binding, you define a query using the
prepare()method, then bind values into the?s usingbind_param(). So given your example, a prepared-statements approach would look like this:On the other hand, with a stored procedure, you simply call it using the
CALLcommand as a normal query:I’m not certain if you can run a
CREATE PROCEDUREusing thequery()method.So to answer your question: yes, it is possible to use both at the same time (because they are different things), but not in the way that you’re imagining, and it would be redundant.