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;
- 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){
- $this->stmt = $this->dbh->prepare($query);
- $this->stmt->execute();
- $result = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
- foreach ($result as $row) {
- $data[] = 'project name: ' . $row['projectName'] . ' tsis: ' . gmdate("H:i",$row['timeSpentInSeconds']) . ' log time: ' . gmdate("d-m-Y",$row['logTime']);
- }
- echo json_encode($data);
- //for($i = 0; $i<count($data); $i++)
- // $data[$i]. '<br/>';
- }
- }
- $db = new Db();
- $db->query('SELECT `projectName`, `timeSpentInSeconds` , `logTime` FROM `projects`, `timesheets` WHERE `timesheets`.`teamuser_id`='.$_GET['id'].' AND `timesheets`.`project_id`=`projects`.`id`');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement