public function start()
{
$timestamp = time();
$query = "
INSERT INTO `stopwatch` (`chat_id`, `timestamp`)
VALUES ('$this->stopwatch_id', '$timestamp')
ON DUPLICATE KEY UPDATE timestamp = '$timestamp'
";
return $this->mysqli->query($query);
}
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("iii", $this->stopwatch_id, $timestamp, $timestamp);
/* execute query */
return $stmt->execute();
}
}