I am working out a function that is meant to query to the database using PDO. I am working with arrays to execute. I am getting error HY093. Below is my code
//my function
function test_function($statement,$data,$connect)
{
$gg = implode(',',$data);
$sth = $connect->prepare($statement);
$sth ->execute(array($gg));
$r_result = $sth->fetch();
$show_result = $r_result['0'];
return $show_result;
}
$datas = array("':ids' => 1"," ':stats' => 1");
$showsh = test_function("SELECT COUNT(*) FROM table WHERE col1 > :ids AND col2 =
:stats",$datas,$con);
echo $showsh;
Any guidance will be helpful.
$datesarray contains 2 strings, not key => value pairs, because you've quoted both. You then turn it into a straight string, and pass it inside another array. This means none of your parameters are being bound.$gg = implode(',',$data);and then$sth ->execute(array($gg));, at which point$ggwill be an array with one comma-separated string (with the keys lost). Whyimplode?