Monday, 12 August 2013

MySQLi bind_param() reference

MySQLi bind_param() reference

I am trying to pass several parameters dynamically to the bind_param()
function.
Here is the error i receive:
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a
reference, value given
CODE:
$con = new mysqli('localhost',USER,PASS,DBS);
if(mysqli_connect_errno()) {
error(mysqli_connect_errno());
}
$con -> set_charset("utf8");
/*inside*/
$type='';
$query='SELECT bugID FROM bug';
if(!empty($_GET['cena'])) {
$build[]='uCena=?';
$type.='i';
$val[]=$_GET['cena'];
}
if(!empty($_GET['popust'])) {
$build[]='uPopust=?';
$type.='i';
$val[]=$_GET['popust'];
}
if(!empty($build)) {
echo $query .= ' WHERE '.implode(' AND ',$build);
}
$new = array_merge(array($type),$val);
foreach($new as $key => $value)
{
$tmp[$key]=&$new[$key];
}
echo '<br/><br/>';
foreach ($new as $new ){
echo "$new<br/>";
}
if ($count = $con->prepare($query)) {
call_user_func_array(array($count,'bind_param'),$tmp);
$count->execute();
$cres = $count->fetch_row();
$count -> close();
} else error($con->error);
/*inside*/
$con -> close();

No comments:

Post a Comment