2

I'm working around for an easy function to execute prepared statement. Now I get a problem:

class mysqli_extend extends \mysqli{
function pquery(){
    $input  = func_get_args();
    if ($stmt   = parent::prepare($input[0])){
        $input  = array_slice($input,1);
        $index = count($input);
        if ($index){ //non-0 == true, 0 == false
            $typestr = '';
            while ($ele = current($input)){
                $type   = gettype($ele);
                switch($type) {
                    case "integer": $typestr .= 'i';    break;
                    case "double":  $typestr .= 'd';    break;
                    case "string":  $typestr .= 's';    break;
                    default:        $typestr .= 'b';    break;
                }
                next($input);
            }
            array_unshift($input,$typestr);

            //output to console checking array content
            while ($ele = current($input)){
                echo key($input) . ":" . $ele . "\t";
                next($input);
            }

            call_user_func_array(array($stmt,'bind_Param'),$input);
        }
        $stmt->execute();
    }
    return true;
}
}

and this is the command to execute:

$test = $mysqli_extend->pquery('UPDATE user_list SET upriv = ? WHERE uname =?','moderator','admin');

while echo statement gives me a correct content of array"0:ss 1:moderator 2:admin" I get error expectedly with: "Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference"

since for the newest php version, it has the problem "Fatal error: Call-time pass-by-reference has been removed"

May I ask whether there is any workaround for this problem?

orb
  • 175
  • 2
  • 13
  • You had a look at this [answer](http://stackoverflow.com/questions/8971261/php-5-4-call-time-pass-by-reference-easy-fix-available)? – ForguesR Jul 25 '14 at 01:48
  • I actually expected there should be a working around to defeat "expected to be a reference" error dodging the &$ symbol... And I'm not sure where I got it wrong :'( – orb Jul 25 '14 at 02:06
  • Can you post the code used to prepare the statement? – ForguesR Jul 25 '14 at 02:17
  • It is exactly the same as the last line of the codes... edited to clarify – orb Jul 25 '14 at 02:19
  • 1
    The examples for: **[mysqli_stmt_bind_param](http://php.net/manual/en/mysqli-stmt.bind-param.php#104073)** explain how to to provide the correct references to **call_user_func_array()** . – Ryan Vincent Jul 25 '14 at 04:29

1 Answers1

0

thanks to ryan vincent, following the link i get the temporary work around although I didn't expect this to work in future:

foreach($input as $k => &$arg){
    $Args[$k] = &$arg;
}
orb
  • 175
  • 2
  • 13