Пытаюсь заменить соединение с базой данных на PDO .
Но не могу понять в чём ошибка.
Мой старый код:
if(ISSET($_POST['search'])){
$idoplata = trim(strip_tags(stripcslashes(htmlspecialchars($_POST["idoplata"]))));
$account_id = trim(strip_tags(stripcslashes(htmlspecialchars($_POST["account_id"]))));
$idaktiv = trim(strip_tags(stripcslashes(htmlspecialchars($_POST["idaktiv"]))));
$account_id = strtok($account_id,' ');
$date1 = date("Y-m-d", strtotime($_POST['date1']));
$date2 = date("Y-m-d", strtotime($_POST['date2']));
$query=mysqli_query($conn, "
SELECT *, account.name AS klient, task.id AS idzakaza, account.id AS idklienta, account.deleted AS del1, task.deleted AS del2, task.name AS zakaz
FROM task
JOIN account ON task.account_id = account.id
WHERE (`date_end` BETWEEN '$date1' AND '$date2') AND account_id Like '%$account_id%' AND priority Like '$idoplata%' AND status Like '$idaktiv%' AND task.deleted=0
")
or die(mysqli_error());
$row=mysqli_num_rows($query);
Мой новый код:
if(ISSET($_POST['search'])){
$idoplata = trim(strip_tags(stripcslashes(htmlspecialchars($_POST["idoplata"]))));
$account_id = trim(strip_tags(stripcslashes(htmlspecialchars($_POST["account_id"]))));
$idaktiv = trim(strip_tags(stripcslashes(htmlspecialchars($_POST["idaktiv"]))));
$account_id = strtok($account_id,' ');
$date1 = date("Y-m-d", strtotime($_POST['date1']));
$date2 = date("Y-m-d", strtotime($_POST['date2']));
$delisf= trim(strip_tags(stripcslashes(htmlspecialchars('0'))));
$dsn = "mysql:host=$dbHost;dbname=$dbName;charset=$dbChar";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, $dbUser, $dbPass, $opt);
$stmt = $pdo->prepare("SELECT account.name AS klient, task.id AS idzakaza, account.id AS idklienta, account.deleted AS del1, task.deleted AS del2, task.name AS zakaz
FROM task
JOIN account ON task.account_id = account.id
WHERE
( date_end BETWEEN ? AND ? )
AND account_id=?
AND priority=?
AND status=?
AND task.deleted=?
");
$stmt->execute([$date1, $date2, $account_id, $idoplata, $idaktiv, $delisf]);
$row = $stmt->rowCount();
Где ошибка в новом коде?