我是 PHP 新手,现在正在使用 PDO 来使我的网站更安全,但是当我使用 fetchcolumn() 时,while 循环无法正常工作。 它不会返回所有行。
这是我的代码
$stmt = $pdo->prepare("SELECT * FROM impdate where joblink=? and status='y' order by id desc");
if ($stmt->execute(array($joblink))) {
$rows = $stmt->fetchColumn();
if ($rows == "") {
echo '<style type="text/css">.impdate{display: none;}</style>';
}else{
while ($row = $stmt->fetch()) {
echo'<tr><td>'.$row['title'].'</td> <td>'.$row['date'].'</td></tr>';
}
}
}
请帮帮我......
注意:当我删除 fetchcolumnl 并仅运行 while 循环时,它可以正常工作
最佳答案
试试这个
use $rows = $stmt->rowCount(); instead of $rows = $stmt->fetchColumn();
$rows = $stmt->fetchColumn();用于仅获取单行。
关于php - 使用 fetchcolumn() while 循环在 pdo 中无法正常工作后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928545/