A
A
alestro2015-10-02 17:56:18
PHP
alestro, 2015-10-02 17:56:18

How to wrap mysqli_stmt_bind_param function?

The question is:
I want to wrap the mysqli_stmt_bind_param function into a database class method.
the function itself accepts references to variables, in an unlimited number, but how to implement this in the bind method
(pass an unlimited number of arguments to the method)
I tried to solve this way:

public function bind(){
  $this->bind = mysqli_stmt_bind_param($this->prepare, join(', ',func_get_args()));
}

but it gives an error:
mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in
Taki solved the question, if anyone is interested, well, or MB will help, actually here:
public function bind(){
  $param = func_get_args();
  $type = array_shift($param);
  $refarg = array($this->prepare,$type);
   foreach ($param as $key => $value):
            $refarg[] =& $param[$key];
  endforeach;
  $this->bind = call_user_func_array("mysqli_stmt_bind_param", $refarg);
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivanq, 2015-10-02
@Ivanq

Read the error in the request! The number of given arguments is incorrect

A
AlikDex, 2015-10-02
@AlikDex

use PDO

M
Melkij, 2015-10-02
@melkij

That's why I don't like mysqli. Quite inconvenient to use the API. PDO is more convenient.
Read the original doc and its comments: php.net/manual/en/mysqli-stmt.bind-param.php
And in the comments there are at least a few ways to get around this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question