Làm thế nào để bạn kiểm tra xem một giá trị cột là null? mã ví dụ:PHP PDO fetch null
$db = DBCxn::getCxn();
$sql = "SELECT exercise_id, author_id, submission, result, submission_time, total_rating_votes, total_rating_values
FROM submissions
LEFT OUTER JOIN submission_ratings ON submissions.exercise_id=submission_ratings.exercise_id
WHERE id=:id";
$st = $db->prepare($sql);
$st->bindParam(":id", $this->id, PDO::PARAM_INT);
$st->execute();
$row = $st->fetch();
$this->total_rating_votes = $row['total_rating_votes'];
if($this->total_rating_votes == null) // this doesn't seem to work even though there is no record in submission_ratings????
{
...
}
'$ row ['total_rating_votes'];' chứa? –
$ row ['total_rating_votes']; nên chứa NULL vì không có bản ghi nào tồn tại trong bảng submission_ratings. Tôi đã xác minh điều này bằng cách chạy truy vấn trong mysqladmin. – Jacob
Nếu không có hồ sơ, thì hàng $ ['total_rating_votes'] chưa được đặt. Thực hiện print_r ($ row). Bạn nên kiểm tra giá trị trả về của thực thi, sẽ là số lượng các bản ghi được tìm thấy. –