2014-05-17 145 views
0

只有第一個SQL語句返回有效結果。其他人返回0.我不明白爲什麼。我究竟做錯了什麼? 這裏是代碼:PDO返回0而不是rowcount

$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> 
'; 
+4

如果連接查詢字符串中的值,則使用預處理語句毫無意義。這不是準備好的陳述的目的。 –

+0

這並不能解決我的問題。我用$ pdo-> query()替換它,發生同樣的事情。 – Parthanaux

回答

0

我找到了解決方案。我重新安裝MySQL服務器,它的工作。