MEMPERBARUI. Oleh karena itu, saya telah belajar bahwa semua dapat dilakukan dalam satu permintaan
$sql = 'select 1 from table where id = ? and self <=> ? and parent <=> ?';
$stm = $conn->prepare($sql);
$stm->execute([$id,$self,$parent]);
$exists = $stm->fetchColumn();
Anda juga harus mengubah kueri Anda.
$sql = 'select count(id) as exists from table where id = ? and ';
if ($type == 1) {
$sql .= 'self IS NULL and parent IS NULL'
$data = [$id];
} else {
$sql .= 'self = ? and parent = ?';
$data = [$id,$self,$parent];
}
$stm = $conn->prepare($sql);
$stm->execute($data);