HTML and CSS Reference
In-Depth Information
Creating a Room
The first method for the model will save new rooms to the database.
This is a multistep process; this method needs to do the following:
rooms table
Create the new room in the
Retrieve the new room's ID
presenters table (or update the presenter's display name in the case
Add the presenter to the
of a duplicate email)
presenters table
Retrieve the presenter's ID from the
room_owners table.
Map the room's ID to the presenter's ID in the
Add the following bold code to the room model:
class Room_Model extends Model
* Saves a new room to the database
* @param $presenter string The name of the presenter
* @param $email string The presenter's email address
* @param $name string The name of the room
* @return array An array of data about the room
public function create_room( $presenter, $email, $name )
// Creates a new room
$sql = 'INSERT INTO rooms (name) VALUES (:name)';
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':name', $name, PDO::PARAM_STR, 255);
// Gets the generated room ID
$room_id = self::$db->lastInsertId();
// Creates (or updates) the presenter
$sql = "INSERT INTO presenters (name, email)
VALUES (:name, :email)
$stmt = self::$db->prepare($sql);
$stmt->bindParam(':name', $presenter, PDO::PARAM_STR, 255);
$stmt->bindParam(':email', $email, PDO::PARAM_STR, 255);
// Gets the generated presenter ID
$sql = "SELECT id
FROM presenters
WHERE email=:email";
Search WWH ::

Custom Search