I'm trying to make a class that will execute any one of a number of stored procedures with any amount of variables
Im using php and mysqli
- My class enumerates an array and constructs a string based on the number of elements if any
- giving something like this
CALL spTestLogin(?,?)
for example I now need to bind the input from my array using somethin like this:
$stmt->bind_param($this->paramTypes,$this->paramValues);//paramValues is my array
Then if that works I can work on getting my results
Any ideas
-
Look
-
You have to do something like this:
$params=array_merge(array($this->paramTypes, $this->paramValues); call_user_func_array(array($stmt, 'bind_param', $params);
given that
$this->paramTypes
is a string in the format required bymysqli_stmt::bind_param
- if not, you have to create thisstring
parameter first.I don't know if
out
orinout
parameters do work in this case. -
mysqli_stmt::bind_param()
will take a variable number of argumentsAssuming
$this->paramTypes
is also an array holding the correct type character for each variable (one of 'i', 'd', 's', 'b'), you could do something like$params = $this->paramValues; array_unshift($params, implode($this->paramTypes); call_user_func_array( array( $stmt, 'bind_param' ), $params);
Essentially you create an array of the parameters you would normally pass to bind_param(), and then make the call using
call_user_func_array()
There may be a much better way of doing this
Edit: just realised I was beaten to it while writing this, I'll leave this answer here for now in case it is of interest
0 comments:
Post a Comment