반응형
열 값이 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????
{
...
}
해결 방법
모든 답변에 감사드립니다. 약간의 실험 끝에이 코드가 내 문제를 해결했습니다.
$this->total_rating_votes = $row['total_rating_votes'];
if(!isset($this->total_rating_votes)) // this is now true if this record had a NULL value in the DB!!!
{
...
}
참조 페이지 https://stackoverflow.com/questions/2855961
반응형
'MySql' 카테고리의 다른 글
MySQL mysql 데이터베이스에서 두 번째 마지막 행을 얻는 방법 (0) | 2020.11.23 |
---|---|
MySQL의 XML 출력 (0) | 2020.11.23 |
MySQL Error 1130 in mysql (0) | 2020.11.23 |
MySQL What is the difference between BIT and TINYINT in MySQL? (0) | 2020.11.23 |
MySQL PHP-잘못된 사용자 이름 / 암호-올바르게 에코하는 방법 (0) | 2020.11.23 |
댓글