Using mysqli_stmt_bind_param in a class - with variable parameters?
| From: | Christian Heinrich | Date: | Fri, 02 Mar 2007 21:24:12 +0000 |
| Subject: | Using mysqli_stmt_bind_param in a class - with variable parameters? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249742@lists.php.net to get a copy of this message | ||
Hi all,
I would like to ask you if anyone of you ever did something like that or might tell me how to do this.
I am currently switching from PHP4 to PHP5 and mySQL4 to mySQL5.
On account of this, I would like to use the improvements of ext/mysqli instead of the old ext/mysql. So I need to do a rewrite on my database class and as of this, I would like to add new functions such as prepared statements, which are obviously supported by mysqli.
In fact, I would like to write a method within my class like this:
public function bindParam($str_types, &$var_variable)
{
// Code
$mysqli_stmt->bind_param($str_types, $var_variable);
}
This method is supposed to be called like this ($result is an object of that class)
$result->bindParam("s", $username);
$username = "username";
That does work out already, but I would like to add more parameters like this:
$result->bind_param("ssss", $username, $email, $me, $you);
As I don't want to write a method with 50 optional parameters (I needed to add one if I were to use 51 variables), I would like to solve this problem dynamically. In fact, I tried to recall the bind_param method of mysqli_stmt several times, but I have to call it only once as PHP requires me to do this. (I get an error otherwise that the number of variables isn't fitting to the prepared statement)
So I have to pass all parameters in one call.
I also tried eval() but that didn't really work out, either.
Now, my question is: What can I do to solve this problem? Is there any elegant way of doing this?
Thanks in advance for any inspiration (and I hope I could make myself clear).
Yours sincerely
Christian Heinrich