0

/* 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 :/

Edited by ryantroop: Epiphany!

1
Contributor
1
Reply
7
Views
4 Years
Discussion Span
Last Post by ryantroop
0

Yeah.. sooo.. I feel silly.

Probably a better way..

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

my bad... :-/

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.