Skip to content

Commit

Permalink
SQL queries working
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent REY committed Apr 12, 2014
1 parent 13be046 commit 0330085
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 6 additions & 6 deletions attlestar/php/SQLdata.Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public function creatUnivers($data)
{
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "qwertyus");
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "abc123");
$query = $db->prepare("INSERT INTO game (data) VALUES (?)");
$query->execute(array(base64_encode(serialize($data))));
return $db->lastInsertId();
Expand All @@ -13,26 +13,26 @@ public function creatUnivers($data)

public function getUnivers($id_game)
{
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "qwertyus");
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "abc123");
$query = $db->prepare("SELECT data FROM game WHERE ? = id");
$query->execute(array(5));
$query->execute(array($id_game));
$data = $query->fetch();
return unserialize(base64_decode($data['data']));
$db->close();
}

public function setUnivers($id_game, $data)
{
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "qwertyus");
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "abc123");
$query = $db->prepare("UPDATE game SET data=':data' WHERE :id_game = game.id");
$query->execute(array(':data' => serialize($data),
':id_game' => $id_game));
':id_game' => $id_game));
$db->close();
}

public function getPlayer($id_game)
{
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "qwertyus");
$db = new PDO("mysql:host=127.0.0.1;dbname=rush2", "root", "abc123");
$db->prepare("SELECT id, name FROM player game WHERE ? = game.id AND game.id = player.id_game");
foreach ($db->exec($id_game) as $value)
$data[] = $value;
Expand Down
14 changes: 14 additions & 0 deletions attlestar/php/SQLdata.doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SQLdata ---------------------------------------------------------------------->
--> public function creatUnivers(Array $player, $data)
Serialize $data et renvois L'ID de l'enregistrement nouvellement cree.
Lie la partie au joueurs concerné

--> public function getUnivers($id_game)
Renvoie les donnees renregistre dans l'enregistrement $id_game unserializé

--> public function setUnivers($id_game, $data)
Serialize $data et le copie dans l'enregistrement $id_game

--> public function getPlayer($id_game)
Renvoie une array des players lié a la partie $id_game
<---------------------------------------------------------------------- SQLdata

0 comments on commit 0330085

Please sign in to comment.