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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:29:30+00:00 2026-06-13T04:29:30+00:00

I have been using MySQLi and for the most part finding it very useful,

  • 0

I have been using MySQLi and for the most part finding it very useful, bind_param() falls down when it comes to dynamic queries though. Anyway im using

call_user_func_array(array($stmt, 'bind_param'), $array_of_params); 

which allow me to get around this, and my code worked fine. However it was a bit messy as I had various if statements to determine the $array_of_params, something like this

if($switch=="coreSkill_only"){
            $array_of_params[0]='s';
            $array_of_params[1]=&$coreSkill;

        }else if($switch=="region_only"){
            $array_of_params[0]='s';
            $array_of_params[1]=&$region;

        }else if($switch=="coreSkill_region"){
            $array_of_params[0]='si';
            $array_of_params[1]=&$coreSkill;
            $array_of_params[2]=&$region;
        }

So rather than cluttering up the method which deals with the actual query execution I decided to stick all the conditional stuff into its own method like so.

function &generateQueryDropDowns($coreSkill,$region){

$queryDetails=array();

$query="select id,title,location,salary,employer,image from jobs where";
$switch="";
$and=0;

$array_of_params=array();

if($coreSkill!="Any"){
    $query.=" coreSkill=?";
    $and=1;
    $override=1;
    $switch="coreSkill_only";
    $array_of_params[0]='s';
    $array_of_params[1]=&$coreSkill;
}
if($region!="Any"){
        if($and==1){
            $query.=" and";
            $switch="coreSkill_region";
            $array_of_params[0]='si';
            $array_of_params[1]=&$coreSkill;
            $array_of_params[2]=&$region;
        }else{
            $switch="region_only";
            $array_of_params[0]='s';
            $array_of_params[1]=&$region;
        }
    $query.=" region=?";
    $override=1;
}

$queryDetails['query']=$query;
$queryDetails['switch']=$switch;
$queryDetails['override']=$override;
$queryDetails['bind_params']=$array_of_params;


return $queryDetails;
}

And i call it from the original method like so

$foo = &$this->generateQueryDropDowns($coreSkill,$region);
$query=$foo['query'];
$switch=$foo['switch'];
$override=$foo['override'];
$array_of_params=$foo['bind_params'];

if($stmt = $connection->prepare($query)) {
call_user_func_array(array($stmt, 'bind_param'), $array_of_params);
etc....

But i get the following error about references

  PHP Warning:  Parameter 2 to mysqli_stmt::bind_param() expected to be a reference

According to http://www.php.net/manual/en/language.references.return.php

As far as i can work out im doing everything correctly to keep the references intact in the return array?

Any advice is very welcome.

  • 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-06-13T04:29:31+00:00Added an answer on June 13, 2026 at 4:29 am

    Turns out you need to pass the parameters as references too.

    so

    function &generateQueryDropDowns($coreSkill,$region){}
    

    becomes

    function &generateQueryDropDowns(&$coreSkill,&$region){}
    

    and it now works as expected.

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

Sidebar

Related Questions

I am totally confused by mySQLi. Although I have been using procedural mysql calls
I have been using MySQL for 2 years now, yet I still don't know
I just started to work on informix.( I have been using mysql all my
I have been using CI just fine using the MySQL driver. I want to
I have been tasked to develop an interactive website using java & mysql: using
I have been working on on an AJAX chat application using php, mysql. It's
I have been using TortoiseSVN for some time and I really like it. I
I have been using Stanford POS Tagger to tag parts of speech in a
I have been using play 1.2.5rc4 for development of one app and I have
I have been using an API to do some work. This is how I

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.