/* also, read the edit */
So... after painful MySQLi intro to working with MySQL Stored procedures... I have come to the conclusion that the only good way to pass variable length binds is to use eval()

Is this a poor choice? The way I am using it is:

$Conn = new mysqli("", "", "", ""); //foo in the blanks...
$Res = $Conn->prepare("") //call whatever(?,?); //in this case, 2

$Arr = array("i"=>2, "s"=>"age"); //we make/get an assoc array with type=>value of whatever length...
$Types = "";
$Args = array();
foreach ($arr as $k=>$v)
{
    $Types .= $k; //all our types as a string
    array_push($Args, $v); //all our values easily iterable...
};

$cString = '$Res->bind_param(\'' . $Types .'\', ';
foreach ($Args as $k=>$v)
  $cString .= '$' . $v . ', ';

$cString = substr($cString, 0, -2);
$cString .= ');';

eval ($cString);

//from here, we execute, etc... 
//and then reverse the process via...

foreach ($Args as $k=>$v)
    eval ('return $' . $v .';');

//and plop those into "real" variables...

Of course, this is NOT complete by any means, but I'm curious if there is a "better way" than this that does not require PHP version sniffing, or goofy attempts to pass an array by reference that throws weird deprication warnings which turn into errors if omitted...

Granted.. being on GoDaddy's servers makes most PHP programming a pain, but if this is it then it's what I gotta do... any thoughts?

Thanks,

Ryan

edit:

obviously the fatal flaw of this is what if your proc returns more than 2 results, or heaven forbid multiple result sets!

Im having a hard time with MySQLi and Stored Procs :/

Yeah.. sooo.. I feel silly.

Probably a better way..

$query = "whatever($var, $var)";
mysqli->real_escape_string($query);
$res = mysqli->query($query);

my bad... :-/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.