Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.06 KB | None | 0 0
  1. <?php
  2. class configBD
  3.  
  4. {
  5.     private $host;
  6.     private $user;
  7.     private $mdp;
  8.     private $bd;
  9.     private $connect;
  10.     private $port;
  11.     public
  12.  
  13.     function __construct()
  14.         {
  15.         $this->port = '5432';
  16.         $this->host = 'localhost';
  17.  
  18.  
  19.         $this->user = 'mow';
  20.         $this->mdp = 'g3amow';
  21.         $this->bd = 'pt';
  22.  
  23.        
  24.         $this->connect = pg_connect("host=localhost port=5432 dbname=pt user=mow password=g3amow");
  25.         }
  26.  
  27.     public
  28.  
  29.     function getConnect()
  30.         {
  31.         return $this->connect;
  32.         }
  33.  
  34.     public
  35.  
  36.     function query($sql)
  37.         {
  38.         $req = $this->connect->prepare($sql);
  39.         $req->execute();
  40.         return ($req->fetchAll());
  41.         }
  42.  
  43.     public
  44.     function get_id($pseudo)
  45.         {
  46.         $req = pg_query($this->connect, 'SELECT "id" FROM "user" WHERE pseudo =\'' . $pseudo . '\';');
  47.         $id = pg_fetch_assoc($req);
  48.         return $id;
  49.         }
  50.  
  51.     public
  52.  
  53.     function get_user()
  54.         {
  55.         $req = $this->connect->prepare("SELECT * FROM user ;");
  56.         if ($req->execute() === TRUE)
  57.             {
  58.             $result["success"] = 1;
  59.             $result["data"] = array();
  60.             while ($row = $req->fetch(PDO::FETCH_ASSOC))
  61.             {
  62.                 $result["data"][] = $row;
  63.             }
  64.  
  65.             return $result;
  66.             }
  67.           else
  68.             {
  69.             $result["success"] = 0;
  70.             return $result;
  71.             }
  72.         }
  73.  
  74.     public
  75.  
  76.     function add_user($nom, $prenom, $pseudo, $password, $age)
  77.     {
  78.         $req = pg_query($this->connect, 'INSERT INTO "user" ("nom", "prenom", "pseudo", "mdp", "age", "nbPartieJoue", "nbPartieWin") VALUES (\'' . $nom . '\',\'' . $prenom . '\',\'' . $pseudo . '\',\'' . $password . '\',\'' . $age . '\', 0, 0);');
  79.         if ($req)
  80.         {
  81.             $result["success"] = 1;
  82.         }
  83.         else
  84.         {
  85.             $result["success"] = 0;
  86.         }
  87.         return $result;
  88.     }
  89.  
  90.     public
  91.  
  92.     function co_user($pseudo, $password)
  93.         {
  94.         $req = pg_query($this->connect, 'SELECT "mdp", "nom", "prenom", "age" FROM "user" WHERE pseudo = \'' . $pseudo . '\';');
  95.         $res = pg_fetch_assoc($req);
  96.         if (password_verify($password, $res['mdp']))
  97.             {
  98.             $row["success"] = 1;
  99.             $row["nom"] = $res["nom"];
  100.             $row["prenom"] = $res["prenom"];
  101.             $row["age"] = $res["age"];
  102.             }
  103.           else
  104.             {
  105.             $row["success"] = 0;
  106.             }
  107.  
  108.         return $row;
  109.         }
  110.  
  111.     public
  112.  
  113.     function add_link($id1, $id2)
  114.         {
  115.         $req = pg_query($this->connect, 'INSERT INTO "liens" VALUES (\'' . $id1 . '\',\'' . $id2 . '\');');
  116.  
  117.         if ($req)
  118.         {
  119.             $result["success"] = 1;
  120.         }
  121.         else
  122.         {
  123.             $result["success"] = 0;
  124.         }
  125.         return $result;
  126.         }
  127.  
  128.     public
  129.  
  130.     function get_link($id)
  131.         {
  132.         $res["success"]=0;
  133.         //$result["data"] = new array();
  134.        
  135.         $req2 = pg_query($this->connect, 'SELECT "id2" from "liens" where id1 =\'' . $id . '\';');
  136.         if ($req2)
  137.         {
  138.             $res["success"]=1;
  139.             $result["data1"]=pg_fetch_all_columns($req2);/*
  140.             while ($row = pg_fetch_assoc($req2))
  141.             {
  142.                 array_push($result["data"], $row);
  143.             }*/
  144.         }
  145.         $req = pg_query($this->connect, 'SELECT "id1" from "liens" where id2 =\'' . $id . '\';');
  146.         if ($req)
  147.         {
  148.             $res["success"]=1;
  149.             $result["data"]=pg_fetch_all_columns($req);/*
  150.             while ($row = pg_fetch_assoc($req))
  151.             {
  152.                 array_push($result["data"], $row);
  153.             }*/
  154.         }
  155.         foreach($result["data"] as $val)
  156.         {
  157.             $req = pg_query($this->connect, 'SELECT "pseudo", "age" FROM "user" WHERE id =\'' . (int)$val . '\';');
  158.             if ($req)
  159.             {
  160.                 $cmp = pg_num_rows($req);
  161.                 for ($i = 0; $i < $cmp; $i++)
  162.                     {
  163.                     $res["data"][] = pg_fetch_assoc($req, $i);
  164.                 }
  165.             }
  166.         }
  167.         foreach($result["data1"] as $val)
  168.         {
  169.             $req = pg_query($this->connect, 'SELECT "pseudo", "age" FROM "user" WHERE id =\'' . (int)$val . '\';');
  170.             if ($req)
  171.             {
  172.                 $cmp = pg_num_rows($req);
  173.                 for ($i = 0; $i < $cmp; $i++)
  174.                     {
  175.                     $res["data"][] = pg_fetch_assoc($req, $i);
  176.                 }
  177.             }
  178.         }
  179.  
  180.         return $res;
  181.         }
  182.  
  183.     public
  184.  
  185.     function del_link($id1, $id2)
  186.     {
  187.         $req = pg_query($this->connect, 'DELETE FROM liens WHERE (id1 = \'' . $id1 . '\' AND id2 = \'' . $id2 . '\');');
  188.  
  189.         if ($req)
  190.         {
  191.             $result["success"] = 1;
  192.         }
  193.         else
  194.         {
  195.             $result["success"] = 0;
  196.         }
  197.         return $result;
  198.     }
  199.  
  200.     public
  201.  
  202.     function nbPartieJoue($id)
  203.     {
  204.         $req = pg_query($this->connect,'SELECT "nbPartieJoue" from "user" where id = \''.$id.'\';');
  205.         if ($req) {
  206.             $res["success"] = 1;
  207.             $res = pg_fetch_assoc($req);
  208.         }else{
  209.             $res["success"] = 0;
  210.         }
  211.         return $res;
  212.     }
  213.  
  214.     public
  215.  
  216.     function nbPartieWin($id)
  217.     {
  218.         $req = pg_query($this->connect,'SELECT "nbPartieWin" from "user" where id = \''.$id.'\';');
  219.         if ($req) {
  220.             $res["success"] = 1;
  221.             $res = pg_fetch_assoc($req);
  222.         }else{
  223.             $res["success"] = 0;
  224.         }
  225.         return $res;
  226.     }
  227.  
  228.     public
  229.  
  230.     function get_stat($id)
  231.     {
  232.         $req = pg_query($this->connect,'SELECT "nbPartieJoue", "nbPartieWin" from "user" where id = \''.$id.'\';');
  233.         if ($req) {
  234.             $res["success"] = 1;
  235.             $res = pg_fetch_assoc($req);
  236.         }else{
  237.             $res["success"] = 0;
  238.         }
  239.         return $res;
  240.     }
  241.  
  242.  
  243.     public
  244.  
  245.     function ajoutPW($id, $pj, $pw)
  246.     {
  247.         $req = pg_query($this->connect,'UPDATE "user" SET nbPartieJoue = \''.$pj.'\', nbPartieWin = \''.$pw.'\' where id = \''.$id.'\';');
  248.         if ($req) {
  249.             $res["success"] = 1;
  250.         }else{
  251.             $res["success"] = 0;
  252.         }
  253.         return $res;
  254.     }
  255.  
  256.     public
  257.  
  258.     function ajoutP($id, $nbpw, $nbp)
  259.         {
  260.  
  261.     }
  262.  
  263. }
  264. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement