11

I have this exact same code working great on another server:

$mysqli_Cxn = new mysqli($SQL_HOST,$SQL_USER,$SQL_PASS,$SQL_DB);
if($mysqli_Cxn->connect_errno){
echo 'Unable to connect!!';
exit();
}

$userID=12345;
$userFirstName = 'Charley';
$userLocale = 'en_US';

$sql = "UPDATE userProfile SET userFirstName=?, userLocale=? WHERE id=?";

if($stmt = $mysqli_Cxn->prepare($sql)){
 if(!$stmt->bind_param('ssi',$userFirstName,$userLocale,$userID)){
  echo "<br/><br/>Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
 }
 if($stmt->execute()){
  totalAffected=$stmt->affected_rows;
  if($totalAffected>=1){
   echo '<br/><br/>UPDATE OK: Affected rows = '. $totalAffected;
  }
 }else{
  echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
 }
}
$stmt->close();

That code gives me the following output: Execute failed: (1210) Incorrect arguments to mysql_stmt_execute

If I change these two lines:

$sql = "UPDATE userProfile SET userFirstName=?, userLocale=? WHERE id=?";
$stmt->bind_param('ssi',$userFirstName,$userLocale,$userID);

to this:

$sql = "UPDATE userProfile SET userFirstName=?, userLocale='en_US' WHERE id=12345";
$stmt->bind_param('s',$userFirstName);

...then the Update is successful and I don't get any error.

Does anyone know why I can't bind more than one param in this code?

I had this code running perfectly on a Centos 4.9, PHP 5.3.3, MySQL 5.0.91/5.0.91-community-log

I need to run it on my current server which is Centos 6.2, PHP 5.3.10, MySQL 5.0.95-community-log

13
  • why the first parameter is different here ( 'ssi' and 's' )? Is it might be an issue ? Commented Apr 7, 2012 at 11:15
  • He's saying that if he changes it to accept a single parameter it works where the multiple parameters don't. Commented Apr 7, 2012 at 11:24
  • 3
    FYI: I did recompile PHP+mysqli (at least 5 times), and I did an md5sum on the source files (comparing to the server where this code works fine). The only extremely strange thing is that I constantly get the following entry in my error_log "sendmail: Not running with correct effective GID. Is sendmail binary setgid mailtrap?"... but I'm sure that's a completely different issue Commented Apr 7, 2012 at 11:30
  • 2
    Voted up and Favorited. I can't find anything related nor any documentation of any possible changes in PHP versions that might have changed how bind_param works nor any fault in your code. Best of luck buddy, wish I could help :( Looking forward to an answer. Commented Apr 7, 2012 at 11:33
  • 1
    Just incase this helps someone in future... I was getting this error despite using PDO. In my case it was because my PHP logic was flawed and I was unintentionally passing a negative OFFSET in a LIMIT,OFFSET query. Commented Nov 16, 2015 at 16:09

4 Answers 4

2
+75

I did a little research, and it seems like a reported error in the MySQL source in combination with your version of GCC and the optimization flags you use. If you can't change the MySQL version, try recompile MySQL with added -fno-strict-aliasing to your CFLAGS.

See http://bugs.mysql.com/bug.php?id=48284 for some more details

Sign up to request clarification or add additional context in comments.

2 Comments

I'm unable to recompile MySQL on this server (already altered source codes to work around this problem), so if I'm unable to reproduce this problem on my new server during the week, I'll mark this as the correct answer and award the bounty.
Not 100% convinced that this is 100% the correct answer... but I provided my own answer and final conclusion for anyone who might have this issue in the future. Thanks again for your feedback!
1

Final notes on this issue.

I got a new server up and running with the following config:

PHP 5.3.10
MySQL 5.1.61-cll

I enable the new server to accept external connections and tested the same code on the fist server (this time replacing "localhost" for my new server's IP).

It gave me the exact same error when I tried to use more than one param in the query.

Finally I tested the code (with the multiple paramater query) on the new server and it worked without any issue.

My logic might be way off, but I guess the problem is with mysqli's client version:

first server:

printf("Client library version: %d\n", mysqli_get_client_version());
//Output:
//Client library version: 50095 

new server:

printf("Client library version: %d\n", mysqli_get_client_version());
//Output:
//Client library version: 50161 

So I can make two recommendations:

  1. Do yourself a favor and go over to PDO
  2. Want/Have to stick with mysqli only? Make sure your server's mysqli client version is not 50095

Thanks to everyone's comments/help!

PS: I'm using VPS servers with CPanel. I tried to recompile the mysqli client using EasyApache in WHM on the first server - and being a total noob at all of this - I guess I'm stuck with the version provided via Cpanel (until my next upgrade).

Comments

0

I would suggest you that explicitelly cast $userID to integer and retest if it still fails.

Since PHP variables are variant as default, maybe you are running into problems when binding a non string (integer in this case) to the query.

Can you try:

$sql = "UPDATE userProfile SET userFirstName=?, userLocale=? WHERE id=?";
$stmt->bind_param('ssi',$userFirstName,$userLocale,(int)$userID);

2 Comments

Hi StormByte, and thanks for your contribution. I forgot to mention that I did try casting the value... but the problem is strictly related to the fact that I can't add more than one marker (ie. use more than one param) regardless of the type of param or the order in which I try to use them. It still accepts only one (and gives error if >= 2 params)
Oh! I am sorry then, in that case it is beyond my scope :( Try then recompiling (or upgrade) as @jornare suggested if you can.
0

I encountered exactly the same problem.

(Bind parameters did not accept more than one parameter)

My version of mysql using this command:

printf ("Client library Version:% d \ n", mysqli_get_client_version ());

was: 50094

The 50095 version is at issue here to this problem:

https://www.liketly.com/forum/thread/27005/mysqli-bind_param-giving-error-1210-incorrect-arguments-to-mysql_stmt_execute/

After an update to PHP 5.4 to 5.6 (on a shared server) mysql version was also updated and the problem disappeared.

My new mysql version is 50011

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.