Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //header("Content-Type: application/json");
- class Db{
- private $host = 'localhost';
- private $user = 'root';
- private $pass = '';
- private $dbname = 'users';
- private $dbh;
- private $error;
- private $stmt;
- private $json;
- private $data = array();
- private $res = array();
- public function __construct(){
- $dsn = 'mysql:host='. $this->host . ';dbname=' . $this->dbname;
- $options = array(PDO::ATTR_PERSISTENT=>true,PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION);
- try{
- $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
- }catch(PDOEXCEPTION $e)
- {
- echo 'ERROR : ' . $e->getMessage();
- }
- }
- public function query($query, $get){
- $this->stmt = $this->dbh->prepare($query);
- $this->stmt->execute(array(':id' => $get));
- //for($i = 0; $i<count($data); $i++)
- // $data[$i]. '<br/>';
- }
- public function rework(){
- $result = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
- /*foreach ($result as $row) {
- $this->data = array('project name: ' => $row['projectName'], 'tsis: ' => gmdate("H:i",$row['timeSpentInSeconds']), 'logTime: ' => gmdate("d-m-Y",$row['logTime']));
- }*/
- foreach ($result as $name){
- $names [] = $name['projectName'];
- }
- foreach ($result as $value){
- $values [] = array('label' => gmdate("d-m-Y",$value['logTime']), 'values' => round($value['timeSpentInSeconds']/60/60, 2));
- }
- $this->res = array('label' => $names, 'values' => $values);
- }
- public function __get($d){
- return $this->res;
- }
- //('project name: ' . $row['projectName'] . ' tsis: ' . gmdate("H:i",$row['timeSpentInSeconds']) . ' log time: ' . gmdate("d-m-Y",$row['logTime']))
- }
- $get = $_GET['id'];
- $d = array();
- $values;
- $db = new Db();
- $db->query(stripslashes('SELECT `projectName`, `timeSpentInSeconds` , `logTime` FROM `projects`, `timesheets` WHERE `timesheets`.`teamuser_id`= :id AND `timesheets`.`project_id`=`projects`.`id`'), $get);
- $db->rework();
- $values = json_encode($db->__get($d));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement