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 6568567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:29:42+00:00 2026-05-25T14:29:42+00:00

FYI. ended up going with PDO solution as this was simpler. I’m trying to

  • 0

FYI. ended up going with PDO solution as this was simpler.

I’m trying to add a single method to handle all queries to the database. I want the queries to use parameter binding. How do I handle a variable amount of function parameters in mysqli_stmt_bind_param()?

This post here led me to understand the pros of parameter binding.

Here is my example code..where I am currently stuck at is marked.

INPUT PARAMETERS

  $query = "INSERT INTO b0 VALUES (?, ?, ?)"
  $par_arr = {'bookmark', 'http://www.bookmark.com', 'tag'}

PROTOTYPE CODE

  protected static function query($query, $par_arr)
    {
    if($statement=mysqli_prepare(one::$db, $query) 
      {
      mysqli_stmt_bind_param($statement, "s", ...variable amount of parameters...);<----how should this be handled?
      ...
  • 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-25T14:29:43+00:00Added an answer on May 25, 2026 at 2:29 pm

    Update 2: If you experience any further problems with this code, then you should probably follow this advice and use PDO instead.

    This is how you should be using call_user_func_array [docs]:

    protected static function query($query, $types, $values) {
        if($statement = mysqli_prepare(one::$db, $query) {
            $parameters = array_merge(array($statement, $types), $values);    
            call_user_func_array('mysqli_stmt_bind_param', $parameters);
            // ...
        }
    }
    

    where $types is a string indicating the type of each value, as described in the mysqli_stmt_bind_param documentation (call_user_func_array is even mentioned there).


    Update: It seems it is not that easy after all, and you have to create references to the values first:

     foreach($values as $k => $v) {
         $values[$k] = &$v;
     }
    
     $parameters = array_merge(array($statement, $types), $values);
     call_user_func_array('mysqli_stmt_bind_param', $parameters);
     // ...
    

    call_user_func_array is for user defined functions per php.net

    No it’s not. The first parameter is of type callback, and the documentation says (emphasis mine):

    A PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs such as: array(), echo(), empty(), eval(), exit(), isset(), list(), print() or unset().

    Next remark:

    is just used to simplify syntax for passing arrays to user defined functions

    Have you had a look at the examples? Each element of the array you pass to call_user_func_array will be passed as argument to the function you specify. Arrays are the only way to have a collection of values of variable size.

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

Sidebar

Related Questions

FYI - I am a mainframer that moved to the .NET world a couple
-Edit- FYI.. I am converting b&w documents scanned in as greyscale or color. 1)The
I'm considering using Django for a project I'm starting (fyi, a browser-based game) and
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits

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.