The Dev Pages

A knowledge base for simple (and beyond) web applications development




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

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.

  1. Emil Said,

    Hi,

    Great post, I recently ran into this same bug, while trying to make a call to mysqli_stmt_bind_param using call_user_func_array. Have you found any solution that will still allow to bind a variable number of parameters?

    Thanks,

    Emil

  2. Nate Admin Said,

    Unfortunately I never found a work-around to use a variable number of params. Which is still frustrating considering mysqli is the improved mysql library, and 5.3 is the later and improved version of php. You would think more people would have this issue. I wonder if it is a variable length function problem. Maybe you can’t use call_user_func_array for functions with varable length parameters as a result of a bug or some misunderstanding on my part.

    Let me know if you find the solution so I can get link to it and get an unresolved problem off the google search results.

    I ended up recompiling php for snow leopard to be 5.2.8, since I had to recompile it anyways for an image library. And at work we switched to ruby on rails for a backend, so I don’t think I’ll be solving this one.

Add A Comment