Я пытаюсь написать запрос для оператора UNION prepare с предложением IN. Я связываю массив с call_user_func_array (), но результат не отображается. Я думаю, что нет никаких проблем с привязкой массива.
вот мой код
PHP код:
if(isset($_GET['subject'])) //subject is array of subjects
{
$search1 = $_GET['subject'];
echo $subject_count = count($search1);
echo $subject_csph = implode(',', array_fill(0, $subject_count, '?')); // comma-separated placeholders
$total_count = $subject_count * 14;
$total_params = array_merge($search1, $search1, $search1, $search1, $search1,
$search1, $search1);
$param_string = str_repeat('s', $subject_count * 14); // write s chars before i chars
$construct .="(subject in ($subject_csph) or subject in ($subject_csph)
or subject in ($subject_csph) or subject in ($subject_csph) or subject in ($subject_csph)
or subject in (subject_csph) or subject in (subject_csph))";
$stmt = $conn->prepare("(SELECT id,year,name,city FROM student1 WHERE $construct) union all (SELECT id,year,name,city FROM student2 WHERE $construct)");
if($stmt){
array_unshift($total_params, $param_string); // prepend the type values string
$ref = []; // add references
foreach ($total_params as $i => $v) {
$ref[$i] = &$total_params[$i]; // pass by reference as required
}
call_user_func_array([$stmt, 'bind_param'], $ref);
$stmt->execute();
$stmt1->bind_result($id,$year,$name,$city,$id,$year,$name,$city);
$count = 0;
while($stmt1->fetch()){
echo $id;
$count++;
}
echo $foundnum=$count;
}
}
в журнале ошибок нет ошибок. что не так я здесь делаю?