You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/Website/gateways/GatewayLobby.php

61 lines
1.5 KiB

<?php
namespace gateways;
use usages\Connection;
use \PDO;
class GatewayLobby
{
private $con;
public function __construct()
{
global $dns, $user, $pass;
$this->con = new Connection($dns, $user, $pass);
}
public function addLobby($lobby)
{
$query = "insert into Lobbies(id,name,password,nbPlayer) values (:id,:name,:password,:nbPlayer);";
$this->con->executeQuery(
$query,
array(
':id' => array($lobby->getId(), PDO::PARAM_INT),
':name' => array($lobby->getName(), PDO::PARAM_STR),
':password' => array($lobby->getPassword(), PDO::PARAM_STR),
':nbPlayer' => array($lobby->getNbPlayer(), PDO::PARAM_INT)
)
);
}
public function getLobbies()
{
$query = "SELECT * FROM lobbies;";
$this->con->executeQuery($query);
$results = $this->con->getResults();
return $results;
}
public function getLobbyByName($name)
{
$query = "SELECT * FROM Lobbies WHERE name = :name;";
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
$results = $this->con->getResults();
if ($results == NULL) {
return false;
}
return $results[0];
}
public function deleteLobby($id)
{
$query = "DELETE FROM Lobbies WHERE id = :id;";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
}
}