Now I have convert my query with PDO format. But I must implement the query with old format for little next time. The code is like this:
function mysql_Select($sql) {
$data=array();
$params=func_get_args();
$s=PreparaSQL($sql, $params);
$res = mysql_query($s);
if ($res && mysql_num_rows($res)){
while( $dt = mysql_fetch_object($res)){
$data[]=$dt;
}
return $data;
}
}
function PreparaSQL($sql, $array_param){
unset($array_param[0]);
foreach ($array_param as $k => $v){
$array_param[$k]=mysql_real_escape_string($v); }
return vsprintf( str_replace("params","%s",$sql), $array_param );
}
And execute the function is :
$data=mysql_Select('SELECT concat(id," | ",wh2) as label,Id as kode,wh2 as nama,wh2 as value FROM wh011 where wh2 like %s',$_GET['where']);
echo json_encode($data);
flush();
And output have error with null value. I think the trouble is in this code:
return vsprintf( str_replace("params","%s",$sql), $array_param );
I really don’t know where is the error point.
Thank’s for you answer.
I think you have parameter 1 and 2 the wrong way around.
Try:
Output
I’d suggest just not doing the str_replace… ?