Prepared statement errors with PHP 5.3 and mysqli. call_user_func_array returns null. Type error?
Prepared statements using mysqli seems to be having issues with PHP 5.3. I kept getting null from a prepared statement command that worked fine in PHP 5.2, namely, the mysqli_stmt_bind_param
Null means that the array you passed didn’t match the function signature.
The following worked in php 5.2, but when I updated my Mac to Snow Leopard (PHP 5.3 included) the following function stopped working
call_user_func_array(’mysqli_stmt_bind_param’, array($stmt,’isis’,$args));
I kept getting a null return value (note – different than false). See bottom of the following bug: http://bugs.php.net/bug.php?id=47554&edit=1
"Returns the function result, NULL for an invalid callback, and FALSE for all other errors."
Toying with the array (translates to method signature of the callback function) passed to call_user_func_array was key. After much head banging (on desk) and much head banging (to music) I found that the following made my one specific test query work:
call_user_func_array(’mysqli_stmt_bind_param’, array($stmt,’isis’,(int) $args[2],(string) $args[3],(int) $args[4],(string) $args[5]));
I wonder if the library that mysqli uses is in c (so that mysqli_stmt_bind_param is eventually run at a level where typing needs to be determined), and is requiring typed values that the php is screwing up somewhere in the translation. Or on the mysqli level. And I wonder what other explanations there could be for this behavior.
Usually when code is this buggy it is a developer’s coding errors, but someday I hope to run into a bug that isn’t my fault. On second thought, finding a bug in your development language probably causes a lot more pain in trying to figure it out, so I’m not sure that would be much of an accomplishment.
