我想知道在执行查询后如何处理无数据或错误代码1329。
$stmt = $this->db->prepare('SELECT Username FROM Users WHERE device_id=?');
$stmt->bind_param("s", $device_id);
$flag = $stmt->execute();
$stmt->bind_result($Username);
我希望这段代码能够通过,但是执行后,该标志为真。
答案 0 :(得分:0)
我建议这样做:
$stmt = $this->db->prepare('SELECT Username FROM Users WHERE device_id=?');
$stmt->bind_param("s", $device_id);
$stmt->execute();
$stmt->bind_result($Username);
if($stmt->fetch()) {
echo "Found $Username";
} else {
echo "Did not find any user";
}
$stmt->close();