daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.    
  14.     public function __construct(){
  15.         $dsn = 'mysql:host='. $this->host . ';dbname=' . $this->dbname;
  16.  
  17.         $options = array(PDO::ATTR_PERSISTENT=>true,PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION);
  18.        
  19.         try{
  20.             $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
  21.         }catch(PDOEXCEPTION $e)
  22.         {
  23.             echo 'ERROR : ' . $e->getMessage();
  24.         }
  25.  
  26.     }
  27.     public function query($query){
  28.  
  29.         $this->stmt = $this->dbh->prepare($query);
  30.         $this->stmt->execute();
  31.         $result = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  32.         foreach ($result as $row) {
  33.             $data[] = 'project name: ' . $row['projectName'] . ' tsis: ' . gmdate("H:i",$row['timeSpentInSeconds']) . ' log time: ' . gmdate("d-m-Y",$row['logTime']);
  34.         }
  35.         echo json_encode($data);
  36.         //for($i = 0; $i<count($data); $i++)
  37.         //  $data[$i]. '<br/>';
  38.     }
  39. }
  40.  
  41. $db = new Db();
  42.  
  43. $db->query('SELECT `projectName`, `timeSpentInSeconds` , `logTime` FROM `projects`, `timesheets` WHERE `timesheets`.`teamuser_id`='.$_GET['id'].' AND `timesheets`.`project_id`=`projects`.`id`');
  44.  
  45.  
  46. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top