PDO MYSQL为什么不工作?

时间:2015-05-12 11:15:02

标签: php mysql pdo

我不知道为什么它没有任何帮助? :)

这会返回0;

$stmt3=$db->query('SELECT COUNT(*) as "ilosc" FROM plat_user WHERE `imie`="'.$_POST['imie'].'" AND `nazwisko`="'.$_POST['nazwisko'].'" AND `nip`="'.$_POST['nip'].'" AND `email`="'.$_POST['email'].'" AND `grupa`=1');
$stmt3->execute();
$row3 = $stmt3->fetch();
echo $row3['ilosc']; 

此代码有效且(返回1):

$rowy = mysql_num_rows(mysql_query('SELECT COUNT(*) as "ilosc" FROM plat_user WHERE `imie`="'.$_POST['imie'].'" AND `nazwisko`="'.$_POST['nazwisko'].'" AND `nip`="'.$_POST['nip'].'" AND `email`="'.$_POST['email'].'" AND `grupa`=1'));

生成的查询在phpmyadmin中很好,它返回1我不知道为什么PDO返回0

1 个答案:

答案 0 :(得分:0)

试一试:

$stmt3=$db->query('SELECT COUNT(*) as "ilosc" FROM plat_user WHERE `imie`="'.$_POST['imie'].'" AND `nazwisko`="'.$_POST['nazwisko'].'" AND `nip`="'.$_POST['nip'].'" AND `email`="'.$_POST['email'].'" AND `grupa`=1');
$stmt3->execute();
$row3 = $stmt3->fetch(PDO::FETCH_ASSOC); // changes here
echo $row3['ilosc'];