Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. //header("Content-Type: application/json");
  3. class Db{
  4.     private $host = 'localhost';
  5.     private $user = 'root';
  6.     private $pass = '';
  7.     private $dbname = 'users';
  8.  
  9.     private $dbh;
  10.     private $error;
  11.     private $stmt;
  12.     private $json;
  13.     private $data = array();
  14.   private $res = array();
  15.     public function __construct(){
  16.         $dsn = 'mysql:host='. $this->host . ';dbname=' . $this->dbname;
  17.  
  18.         $options = array(PDO::ATTR_PERSISTENT=>true,PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION);
  19.        
  20.         try{
  21.             $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
  22.         }catch(PDOEXCEPTION $e)
  23.         {
  24.             echo 'ERROR : ' . $e->getMessage();
  25.         }
  26.  
  27.     }
  28.     public function query($query, $get){
  29.  
  30.         $this->stmt = $this->dbh->prepare($query);
  31.         $this->stmt->execute(array(':id' => $get));
  32.         //for($i = 0; $i<count($data); $i++)
  33.         //  $data[$i]. '<br/>';
  34.     }
  35.     public function rework(){
  36.         $result = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  37.         /*foreach ($result as $row) {
  38.              $this->data = array('project name: ' => $row['projectName'], 'tsis: ' => gmdate("H:i",$row['timeSpentInSeconds']), 'logTime: ' => gmdate("d-m-Y",$row['logTime']));
  39.         }*/
  40.     foreach ($result as $name){
  41.       $names [] = $name['projectName'];
  42.     }
  43.     foreach ($result as $value){
  44.       $values [] = array('label' => gmdate("d-m-Y",$value['logTime']), 'values' => round($value['timeSpentInSeconds']/60/60, 2));
  45.     }
  46.     $this->res = array('label' => $names, 'values' => $values);
  47.     }
  48.     public function __get($d){
  49.         return $this->res;
  50.     }
  51.     //('project name: ' . $row['projectName'] . ' tsis: ' . gmdate("H:i",$row['timeSpentInSeconds']) . ' log time: ' . gmdate("d-m-Y",$row['logTime']))
  52. }
  53. $get = $_GET['id'];
  54. $d = array();
  55. $values;
  56. $db = new Db();
  57.  
  58. $db->query(stripslashes('SELECT `projectName`, `timeSpentInSeconds` , `logTime` FROM `projects`, `timesheets` WHERE `timesheets`.`teamuser_id`= :id AND `timesheets`.`project_id`=`projects`.`id`'), $get);
  59. $db->rework();
  60. $values = json_encode($db->__get($d));
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement