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

  • Home
  • SEARCH
  • 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 599899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:32:54+00:00 2026-05-13T16:32:54+00:00

I’m trying to use call_user_func_array and mysqli_stmt::bind_param like so: # A. prepare an insert

  • 0

I’m trying to use call_user_func_array and mysqli_stmt::bind_param like so:

# A. prepare an insert query statement
$this->_stmt = $db_link->prepare('INSERT INTO foo (col1, col2) VALUES (?,?)');

# B. bind a placeholder array to the statement
$bound = array('col1' => null, 'col2' => null);
call_user_func_array(array($this->_stmt, 'bind_param'), 
  array($types_string, &$bound));

# C. while there are records, retrieve, munge, and insert
while ($row = $res->fetch_assoc()) {
  $bound = transform($row); # $bound remains an array indexed as 'col1', 'col2'
  $this->_stmt->execute();  # PHP Notice:  Array to string conversion
}

I’m getting confused by PHP references, leading to the array to string conversion. Either I’m not binding the placeholder array correctly under step B, or I’m not assigning to the placeholder correctly in step C.

(Similar questions have been asked before, but I haven’t found an answer to mine.)

  • 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-13T16:32:55+00:00Added an answer on May 13, 2026 at 4:32 pm

    You’re passing

    array(
      types,
      &array(
        a, b, c
      )
    )
    

    to call_user_func_array() but it has to be

    array(
      types, &a, &b, &c
    )
    

    One way to accomplish that is to use another (temporary) array with all the elements of the “original” array as references. http://docs.php.net/call_user_func_array:

    Note: Referenced variables in param_arr are passed to the function by a reference, others are passed by a value. […]

    E.g.

    $mysql = new mysqli('localhost', 'localonly', 'localonly', 'test');
    // test table
    $mysql->query('CREATE TEMPORARY TABLE foo (a int, b int, c int)') or die($mysql->error);
    
    $params = array('a'=>null, 'b'=>null, 'c'=>null);
    $types = 'iii';
    
    $stmt = $mysql->prepare('INSERT INTO foo (a,b,c) VALUES (?,?,?)');
    // make an array of references to the original array
    $tmp = array($types);
    foreach( $params as &$p ) {
      $tmp[] = &$p;
    }
    call_user_func_array( array($stmt, 'bind_param'), $tmp);
    
    // test insert
    for($i=0; $i<10; $i++) {
      $params['a'] = $i;
      $params['b'] = $i+100;
      $params['c'] = $i+1000;
      $stmt->execute();
    }
    unset($stmt);
    
    // test select
    $result = $mysql->query('SELECT * FROM foo');
    while( null!==($row=$result->fetch_row()) ) {
      echo join(',', $row), "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.