1

I have this code

public function bind_array($array) {
    $array=[1,"bob"];
    $type = '';

    foreach ( $array as $var ) {
        switch (true) {
            case is_int ( $var ) :
                $type .= "i";
                break;
            case is_double ( $var ) :
                $type .= "d";
            default :
                $type .= "s";
        }
    }

    $param_array [] = &$type;

    for($i = 0; $i < count ( $array ); $i ++) {
        $param_array [] = &$array [$i];
    }

    call_user_func ( array ($this->stmt,'bind_param' ), $param_array );
}

and I always get the error wrong parameter count. What is the mistake here?

If I change the last line into

call_user_func ( array ($this->stmt,'bind_param' ), 'is',1,"bob" );

Everything is ok.

Thanks for helping.

1 Answer 1

1

Just use call_user_func_array instead of call_user_func since you're passing an array.

call_user_func_array ( array ($this->stmt,'bind_param' ), $param_array );

Here are the official docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.