PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE `stopwatch` (`chat_id` int, `timestamp` int);
Copy Clear
Copy Format Clear
<?php $_ENV['BD_NAME'] = '080a06bd157cb3e0b00501b43b43bade'; class Stopwatch { private $mysqli; private $stopwatch_id; private $db; function __construct($mysqli, $stopwatch_id) { $this->db = $_ENV['BD_NAME']; $this->mysqli = $mysqli; $this->stopwatch_id = $stopwatch_id; } public function start() { $timestamp = time(); $query = " INSERT INTO `$this->db`.`stopwatch` (`chat_id`, `timestamp`) VALUES (?, ?) ON DUPLICATE KEY UPDATE timestamp = ? "; $stmt = $this->mysqli->prepare($query); /* bind parameters for markers */ $stmt->bind_param("ddd", $this->stopwatch_id, $timestamp, $timestamp); /* execute query */ return $stmt->execute(); } public function getTime() { $timestamp = time(); $query = " SELECT `timestamp` FROM `$this->db`.`stopwatch` WHERE `chat_id` = ? "; $stmt = $this->mysqli->prepare($query); /* bind parameters for markers */ $stmt->bind_param("d", $this->stopwatch_id); /* execute query */ $stmt->execute(); $stmt->bind_result($startTime); /* fetch values */ $stmt->fetch(); return $startTime; } } $sw = new Stopwatch($mysqli, 1); $sw->start(); echo $sw->getTime();
Show:  
Copy Clear