• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

call stored mySQL Procedure

#1
Hello,

After many hours trying to figure out on my own how to call a procedure with parameters from an extended Xenforo PHP class - I have to ask you guys for help :oops:

Calling a procedure without parameters or with hardcoded parameters works fine!
Code:
$stmt = $db->prepare('CALL my_procedure_test(2)');
$stmt->execute();
$rows = $stmt->fetchAll();
But how to call the procedure with the bindParam command :confused:
PHP:
$stmt = $db->prepare('CALL my_procedure_test(?)');
$stmt->bindParam(1, 5);
$stmt->execute();
$rows = $stmt->fetchAll();
I also tryed the syntax for the parameter like
Code:
:param1 instead of "?"
But it always fails:(

So please tell me whats the correct syntax to call the procedure with bindParam from Xenforo with the default db-Adapter.

thX Erich
 

Jim Boy

Well-known member
#2
why dont you try
PHP:
$stmt = $db->prepare('CALL my_procedure_test(?)');
$stmt->execute(array(5));
$rows = $stmt->fetchAll();
 

Jim Boy

Well-known member
#3
Also I supect bind doesn't numbers, try :var instead of ?

eg
PHP:
$stmt = $db->prepare('CALL my_procedure_test(:var)');
$stmt->bindParam("var", 5);
 
#4
@Jim Boy sadly also your methodes are not working :confused:
I googled so much and none of the syntaxes works :eek:

I know the Zend Framework is used - but how should I call the procedure with the parameters?

For your first solution I get following error
Code:
ErrorException: Array to string conversion - library\...\UserRegistrationCT.php:62
For the 2nd Solution, which I tryed also before, but it always failed because of the ":" before the parameter.
Code:
Zend_Db_Statement_Mysqli_Exception: Mysqli prepare error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':param1)' at line 1 - library\Zend\Db\Statement\Mysqli.php:77
PHP:
$stmt = $db->prepare('CALL my_procedure_test(:param1)');
$stmt->bindValue(":param1", 7);
$stmt->execute();
$rows = $stmt->fetchAll();
I am happy for every tested hint ;)
With such a small problem I struggle around 2 days :cry:

Erich