HTML and CSS Reference
In-Depth Information
$sql = "SELECT COUNT(id) AS the_count FROM rooms WHERE id = :room_id";
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':room_id', $room_id, PDO::PARAM_INT);
$stmt->execute();
$room_exists = (bool) $stmt->fetch(PDO::FETCH_OBJ)->the_count;
$stmt->closeCursor();
return $room_exists;
}
}
Using (bool) to explicitly cast the count as a Boolean value means that this method will always return TRUE or
FALSE , which is helpful for a method whose sole purpose is to check if something exists.
Opening a Room
For a room that has been closed, opening it again is as simple as setting the is_active column to 1 in the rooms table
for the room with the given ID.
Add the code shown in bold to class.room_model.inc.php :
$room_exists = (bool) $stmt->fetch(PDO::FETCH_OBJ)->the_count;
$stmt->closeCursor();
return $room_exists;
}
/**
* Sets a given room's status to "open"
*
* @param $room_id int The ID of the room being checked
* @return array An array of data about the room
*/
public function open_room( $room_id )
{
$sql = "UPDATE rooms SET is_active=1 WHERE id = :room_id";
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':room_id', $room_id, PDO::PARAM_INT);
$stmt->execute();
$stmt->closeCursor();
return array(
'room_id' => $room_id,
);
}
}
 
Search WWH ::




Custom Search