Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class configBD
- {
- private $host;
- private $user;
- private $mdp;
- private $bd;
- private $connect;
- private $port;
- public
- function __construct()
- {
- $this->port = '5432';
- $this->host = 'localhost';
- $this->user = 'mow';
- $this->mdp = 'g3amow';
- $this->bd = 'pt';
- $this->connect = pg_connect("host=localhost port=5432 dbname=pt user=mow password=g3amow");
- }
- public
- function getConnect()
- {
- return $this->connect;
- }
- public
- function query($sql)
- {
- $req = $this->connect->prepare($sql);
- $req->execute();
- return ($req->fetchAll());
- }
- public
- function get_id($pseudo)
- {
- $req = pg_query($this->connect, 'SELECT "id" FROM "user" WHERE pseudo =\'' . $pseudo . '\';');
- $id = pg_fetch_assoc($req);
- return $id;
- }
- public
- function get_user()
- {
- $req = $this->connect->prepare("SELECT * FROM user ;");
- if ($req->execute() === TRUE)
- {
- $result["success"] = 1;
- $result["data"] = array();
- while ($row = $req->fetch(PDO::FETCH_ASSOC))
- {
- $result["data"][] = $row;
- }
- return $result;
- }
- else
- {
- $result["success"] = 0;
- return $result;
- }
- }
- public
- function add_user($nom, $prenom, $pseudo, $password, $age)
- {
- $req = pg_query($this->connect, 'INSERT INTO "user" ("nom", "prenom", "pseudo", "mdp", "age", "nbPartieJoue", "nbPartieWin") VALUES (\'' . $nom . '\',\'' . $prenom . '\',\'' . $pseudo . '\',\'' . $password . '\',\'' . $age . '\', 0, 0);');
- if ($req)
- {
- $result["success"] = 1;
- }
- else
- {
- $result["success"] = 0;
- }
- return $result;
- }
- public
- function co_user($pseudo, $password)
- {
- $req = pg_query($this->connect, 'SELECT "mdp", "nom", "prenom", "age" FROM "user" WHERE pseudo = \'' . $pseudo . '\';');
- $res = pg_fetch_assoc($req);
- if (password_verify($password, $res['mdp']))
- {
- $row["success"] = 1;
- $row["nom"] = $res["nom"];
- $row["prenom"] = $res["prenom"];
- $row["age"] = $res["age"];
- }
- else
- {
- $row["success"] = 0;
- }
- return $row;
- }
- public
- function add_link($id1, $id2)
- {
- $req = pg_query($this->connect, 'INSERT INTO "liens" VALUES (\'' . $id1 . '\',\'' . $id2 . '\');');
- if ($req)
- {
- $result["success"] = 1;
- }
- else
- {
- $result["success"] = 0;
- }
- return $result;
- }
- public
- function get_link($id)
- {
- $res["success"]=0;
- //$result["data"] = new array();
- $req2 = pg_query($this->connect, 'SELECT "id2" from "liens" where id1 =\'' . $id . '\';');
- if ($req2)
- {
- $res["success"]=1;
- $result["data1"]=pg_fetch_all_columns($req2);/*
- while ($row = pg_fetch_assoc($req2))
- {
- array_push($result["data"], $row);
- }*/
- }
- $req = pg_query($this->connect, 'SELECT "id1" from "liens" where id2 =\'' . $id . '\';');
- if ($req)
- {
- $res["success"]=1;
- $result["data"]=pg_fetch_all_columns($req);/*
- while ($row = pg_fetch_assoc($req))
- {
- array_push($result["data"], $row);
- }*/
- }
- foreach($result["data"] as $val)
- {
- $req = pg_query($this->connect, 'SELECT "pseudo", "age" FROM "user" WHERE id =\'' . (int)$val . '\';');
- if ($req)
- {
- $cmp = pg_num_rows($req);
- for ($i = 0; $i < $cmp; $i++)
- {
- $res["data"][] = pg_fetch_assoc($req, $i);
- }
- }
- }
- foreach($result["data1"] as $val)
- {
- $req = pg_query($this->connect, 'SELECT "pseudo", "age" FROM "user" WHERE id =\'' . (int)$val . '\';');
- if ($req)
- {
- $cmp = pg_num_rows($req);
- for ($i = 0; $i < $cmp; $i++)
- {
- $res["data"][] = pg_fetch_assoc($req, $i);
- }
- }
- }
- return $res;
- }
- public
- function del_link($id1, $id2)
- {
- $req = pg_query($this->connect, 'DELETE FROM liens WHERE (id1 = \'' . $id1 . '\' AND id2 = \'' . $id2 . '\');');
- if ($req)
- {
- $result["success"] = 1;
- }
- else
- {
- $result["success"] = 0;
- }
- return $result;
- }
- public
- function nbPartieJoue($id)
- {
- $req = pg_query($this->connect,'SELECT "nbPartieJoue" from "user" where id = \''.$id.'\';');
- if ($req) {
- $res["success"] = 1;
- $res = pg_fetch_assoc($req);
- }else{
- $res["success"] = 0;
- }
- return $res;
- }
- public
- function nbPartieWin($id)
- {
- $req = pg_query($this->connect,'SELECT "nbPartieWin" from "user" where id = \''.$id.'\';');
- if ($req) {
- $res["success"] = 1;
- $res = pg_fetch_assoc($req);
- }else{
- $res["success"] = 0;
- }
- return $res;
- }
- public
- function get_stat($id)
- {
- $req = pg_query($this->connect,'SELECT "nbPartieJoue", "nbPartieWin" from "user" where id = \''.$id.'\';');
- if ($req) {
- $res["success"] = 1;
- $res = pg_fetch_assoc($req);
- }else{
- $res["success"] = 0;
- }
- return $res;
- }
- public
- function ajoutPW($id, $pj, $pw)
- {
- $req = pg_query($this->connect,'UPDATE "user" SET nbPartieJoue = \''.$pj.'\', nbPartieWin = \''.$pw.'\' where id = \''.$id.'\';');
- if ($req) {
- $res["success"] = 1;
- }else{
- $res["success"] = 0;
- }
- return $res;
- }
- public
- function ajoutP($id, $nbpw, $nbp)
- {
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement