Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:19:08+00:00 2026-05-26T19:19:08+00:00

I’m basically trying to call mysqli::bind_param via call_user_func_array . Here’s my function: function Insert($table,

  • 0

I’m basically trying to call mysqli::bind_param via call_user_func_array.

Here’s my function:

function Insert($table, $values=array(), $flags=0) {
    $field_count = count($values);
    
    if($field_count > 0) {
        $fields = implode(',',array_keys($values));
        $placeholders = implode(',',array_repeat('?',$field_count));
    } else {
        $fields = '';
        $placeholders = '';
    }

    if($flags > 0) {
        $flag_arr = array();
        if($flags & self::LOW_PRIORITY) $flag_arr[] = 'LOW_PRIORITY';
        if($flags & self::DELAYED) $flag_arr[] = 'DELAYED';
        if($flags & self::HIGH_PRIORITY) $flag_arr[] = 'HIGH_PRIORITY';
        if($flags & self::IGNORE) $flag_arr[] = 'IGNORE';
        $flags_str = implode(' ',$flag_arr);
    } else {
        $flags_str = '';
    }
    
    $sql = "INSERT $flags_str INTO $table ($fields) VALUES ($placeholders)";
    $stmt = $this->mysqli->prepare($sql);
    if($stmt === false) {
        throw new Exception('Error preparing MySQL statement.<br/>MSG: '.$this->mysqli->error.'<br/>SQL: '.$sql);
    }
    
    if($field_count > 0) {
        $types = '';
        foreach($values as $val) {
            if(is_int($val)) $types .= 'i';
            elseif(is_float($val)) $types .= 'd';
            elseif(is_string($val)) $types .= 's';
            else $types .= 'b';
        }
        $params = array_merge(array($types),array_values($values));
        call_user_func_array(array($stmt,'bind_param'),$params);
    }
    
    $stmt->execute();
    return $stmt;
}

The problem occurs on the call_user_func_array line. I get this error:

Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given

I understand the problem, I’m just not sure how to work around it.

As an example, the function may be called like this:

$db->Insert('pictures',array('views'=>1));

And var_dump($params) would yield this:

array
  0 => string 'i' (length=1)
  1 => int 1

So, is there a way to call mysqli::bind_param with a variable number of arguments, or somehow make my array into references?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:19:09+00:00Added an answer on May 26, 2026 at 7:19 pm

    The second note in the manual page for mysqli_stmt::bind_param() states:

    Care must be taken when using mysqli_stmt_bind_param() in conjunction with call_user_func_array(). Note that mysqli_stmt_bind_param() requires parameters to be passed by reference, whereas call_user_func_array() can accept as a parameter a list of variables that can represent references or values.

    There is a solution posted in the user-comments section in the manual. In short, you make a function that accepts an array and returns a duplicate array whose elements are references to the elements in the source array.

    Edit: Turns out there are a couple SO questions on this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.