MYSQLI 预处理语句白页
MYSQLI Prepared Statement White Page
我正在尝试将一些 PHP 通知代码转换为更合适的 Prepared 语句。无论我尝试什么,它都会破坏我的页面。有没有人能告诉我错误在哪里?
EDIT 页面并非完全空白。此代码后分页。
$acctNotsQry = $redoDB->prepare('SELECT message, nDate FROM notifications WHERE uID = ? AND nSeen = "0" ORDER BY nDate DESC');
$acctNotsQry->bind_param('i', intval($memID));
$acctNotsQry->execute();
$acctNotsQry->store_result();
$acctNotsQry->bind_result($notMessage, $notnDate);
if($acctNotsQry->num_rows == 0){
echo '<li><div class="nilNots">NO NOTIFICATIONS</div></li>';
} else {
while($acctNotsQry->fetch()) {
?>
<li><i class="fa fa-bell"></i> <?php echo htmlspecialchars_decode(stripslashes($notMessage)); ?>
<p><?php echo date('d M Y - h:ia', strtotime($notnDate)); ?></p></li>
<?php
}
}
$acctNotsQry->close();
第二次编辑: 以下代码有效,上面的无效。它可能有助于解决问题:
$acctNotsQry = 'SELECT * FROM notifications WHERE uID = "'.$memID.'" AND nSeen = "0" ORDER BY nDate DESC';
$acctNotsRes = $redoDB->query($acctNotsQry);
$acctNotsNum = $acctNotsRes->num_rows;
if($acctNotsNum == 0){
echo '<li><div class="nilNots">NO NOTIFICATIONS</div></li>';
} else {
while($acctNotsRow = $acctNotsRes->fetch_assoc()){
$notMsg = $acctNotsRow['message'];
?>
<li><i class="fa fa-bell"></i> <?php echo htmlspecialchars_decode(stripslashes($notMsg)); ?>
<p><?php echo date('d M Y - h:ia', strtotime($acctNotsRow['nDate'])); ?></p></li>
<?php
}
}
我试过寻找解决方案无济于事。
非常感谢。
改变
$acctNotsQry->bind_param('i', intval($memID));
到
$acctNotsQry->bind_param('i', $memID);
bind_param
的第二个和后面的参数是引用参数,所以你必须在那里使用变量,而不是表达式。您不需要自己调用 intval()
,第一个参数中的 i
类型告诉 mysqli 在将其发送到 MySQL.
时将其转换为整数
我正在尝试将一些 PHP 通知代码转换为更合适的 Prepared 语句。无论我尝试什么,它都会破坏我的页面。有没有人能告诉我错误在哪里?
EDIT 页面并非完全空白。此代码后分页。
$acctNotsQry = $redoDB->prepare('SELECT message, nDate FROM notifications WHERE uID = ? AND nSeen = "0" ORDER BY nDate DESC');
$acctNotsQry->bind_param('i', intval($memID));
$acctNotsQry->execute();
$acctNotsQry->store_result();
$acctNotsQry->bind_result($notMessage, $notnDate);
if($acctNotsQry->num_rows == 0){
echo '<li><div class="nilNots">NO NOTIFICATIONS</div></li>';
} else {
while($acctNotsQry->fetch()) {
?>
<li><i class="fa fa-bell"></i> <?php echo htmlspecialchars_decode(stripslashes($notMessage)); ?>
<p><?php echo date('d M Y - h:ia', strtotime($notnDate)); ?></p></li>
<?php
}
}
$acctNotsQry->close();
第二次编辑: 以下代码有效,上面的无效。它可能有助于解决问题:
$acctNotsQry = 'SELECT * FROM notifications WHERE uID = "'.$memID.'" AND nSeen = "0" ORDER BY nDate DESC';
$acctNotsRes = $redoDB->query($acctNotsQry);
$acctNotsNum = $acctNotsRes->num_rows;
if($acctNotsNum == 0){
echo '<li><div class="nilNots">NO NOTIFICATIONS</div></li>';
} else {
while($acctNotsRow = $acctNotsRes->fetch_assoc()){
$notMsg = $acctNotsRow['message'];
?>
<li><i class="fa fa-bell"></i> <?php echo htmlspecialchars_decode(stripslashes($notMsg)); ?>
<p><?php echo date('d M Y - h:ia', strtotime($acctNotsRow['nDate'])); ?></p></li>
<?php
}
}
我试过寻找解决方案无济于事。 非常感谢。
改变
$acctNotsQry->bind_param('i', intval($memID));
到
$acctNotsQry->bind_param('i', $memID);
bind_param
的第二个和后面的参数是引用参数,所以你必须在那里使用变量,而不是表达式。您不需要自己调用 intval()
,第一个参数中的 i
类型告诉 mysqli 在将其发送到 MySQL.