12

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

Charley P.
  • 184
  • 1
  • 13
  • why the first parameter is different here ( 'ssi' and 's' )? Is it might be an issue ? – sarwar026 Apr 07 '12 at 11:15
  • He's saying that if he changes it to accept a single parameter it works where the multiple parameters don't. – Menztrual Apr 07 '12 at 11:24
  • first I tried with 3 params (string, string, int)... and then with only one (string) which worked. So for some reason it's not accepting more than one (ie. it also didn't work when I tried with only the first two params: ('ss',$userFirtName,$userLocale) – Charley P. Apr 07 '12 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 – Charley P. Apr 07 '12 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. – Menztrual Apr 07 '12 at 11:33
  • @tehlulz Thanks. I really did my best to find an answer before posting... I'm completely clueless – Charley P. Apr 07 '12 at 11:36
  • As am I. :/ My only suggestion I had was to reinstall mysqli and PHP, but great minds think alike ;) – Menztrual Apr 07 '12 at 11:37
  • Why are you checking for an error if `execute()` returns `true`? Also, have you tried downgrading MySQL to version 5.0.91? – leemeichin Apr 09 '12 at 15:18
  • Which client version? http://www.php.net/manual/en/mysqli.get-client-version.php – hakre Apr 11 '12 at 23:48
  • oddly, I ran into an issue like this and placing \`...\` around columns names helped: `$sql = "UPDATE userProfile SET \`userFirstName\`=?, \`userLocale\`=? WHERE \`id\`=?";` – Matisse VerDuyn Apr 12 '12 at 20:33
  • @hakre Client library version = 50095 – Charley P. Apr 15 '12 at 16:53
  • @MatisseVerDuyn Didn't work :( – Charley P. Apr 15 '12 at 16:53
  • 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. – carpii Nov 16 '15 at 16:09

4 Answers4

3

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

jornare
  • 2,903
  • 19
  • 27
  • 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. – Charley P. Apr 15 '12 at 17:38
  • 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! – Charley P. Apr 21 '12 at 05:44
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).

Charley P.
  • 184
  • 1
  • 13
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);
StormByte
  • 1,266
  • 1
  • 13
  • 33
  • 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) – Charley P. Apr 11 '12 at 04:17
  • Oh! I am sorry then, in that case it is beyond my scope :( Try then recompiling (or upgrade) as @jornare suggested if you can. – StormByte Apr 11 '12 at 08:08
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

user2267379
  • 1,067
  • 2
  • 10
  • 20