只有第一个SQL语句返回有效结果。其他人返回0.我无法弄清楚原因。我究竟做错了什么? 这是代码:
$year = htmlspecialchars($_POST['year']);
$ukupan_broj_servisa="SELECT COUNT(*) FROM services WHERE date BETWEEN '$year-01-01' AND '$year-12-31'";
$ukupan_broj_malih_servisa="SELECT COUNT(*) FROM services WHERE service_mali > '' AND date BETWEEN '$year-01-01' AND '$year-12-31'";
$ukupan_broj_velikih_servisa="SELECT COUNT(*) FROM services WHERE service_veliki > '' AND date BETWEEN '$year-01-01' AND '$year-12-31'";
$ukupan_broj_kola="SELECT COUNT(*) FROM cars";
$stmtser = $pdo->prepare($ukupan_broj_servisa);
$stmtmali = $pdo->prepare($ukupan_broj_malih_servisa);
$stmtveliki = $pdo->prepare($ukupan_broj_velikih_servisa);
$stmtkola = $pdo->prepare($ukupan_broj_kola);
try {
$stmtser->execute();
$stmtmali->execute();
$stmtveliki->execute();
$stmtkola->execute();
} catch (PDOException $e) {
echo "Došlo je do greške u bazi podataka. Molimo pokušajte kasnije ili kontaktirajte administratora.";
echo $e;
exit();
}
echo '
<label id="brojvozila">'.$stmtkola->fetchColumn(0).'</label>
<label id="brojservisa">'.$stmtser->fetchColumn(0).'</label>
<label id="brojmalihservisa">'.$stmtmali->fetchColumn(0).'</label>
<label id="brojvelikihservisa">'.$stmtveliki->fetchColumn(0).'</label>
';
答案 0 :(得分:0)
我找到了解决方案。我重新安装了MySQL服务器并且工作正常。