Jump to content

mysqli_stmt_bind_param help - please


danlatario

Recommended Posts

Hi All,

 

I been stuck on a problem for a bit now and cant really find an answer so I hope someone knows here.

 

I have the following code:

 

function db_query_prepare($dbh, $sql, $args) {



  $dbst = mysqli_prepare($dbh, $sql);

  if(!$dbst) {return 0;}

  

  foreach($args as $arg) {

    mysqli_stmt_bind_param($dbst, "i", $arg);

  }



  mysqli_stmt_execute($dbst);

  mysqli_stmt_store_result($dbst);



  return $dbst;

}



$result = db_query_prepare($db, "SELECT firstname FROM profile WHERE profileID = ? AND statusID = ? LIMIT 1", array(55, 3)); 

 

the above was taken from the book: php cookbook2

(For now assume all values are integers)

 

I have code very similar to the that above, my question is simple, is this code correct? I can get the code to work with a single ? (placeholder), but it throws a "Number of variables doesn't match number of parameters in prepared statement in .." warning/error, I know there is a form of the function that is as follows:

 

mysqli_stmt_bind_param($dbst, 'ii', 55, 54 ) 

 

But my problem is I may not know the parameters in advance so I just want to pass db_query_prepare the sql and needed values in an array? looking at the above code taken from the book implies that it indeed can be done, but I just get the same error, I have also tried implode, to return a string 1,2,3 etc, but still I get the above error?

 

I have done a bit of searching, and there are reported bugs giving the same error, but I have upgraded libraries as suggested but still to no avail?

 

MySqli details:

Client version: 50045

Server version: 50041

 

The only solution I have found is to build a string and execute it using eval!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.