我正在创建 Flash 游戏,其中计时器计算玩家玩了多长时间,在游戏随时间变量发送到 php 之后,我需要从这里将它插入数据库。时间格式是 MM:SS(例如 01:17),但是到数据库中总是插入 0。我不知道我需要选择哪种类型的“时间”列,我尝试了“INT”,“时间”,但是相同,始终为“0”。你可以帮帮我吗?谢谢。
这是我的代码:
$time = $_POST['time'];
$username = $_POST['userName'];
session_start();
$name = $_SESSION['vardas'];
$times = gmdate('i:s', $time);
$mysqli = new mysqli("localhost","my_db","pass","my_db");
if ($stmt = $mysqli->prepare("INSERT into eurokos (time, userName) VALUE (?,?) ")) {
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
$stmt->bind_param('is', $times, $name);
// $stmt->bind_param("s", $username);
$stmt->execute();
if ($stmt->error != '') {
echo ' error:'.$stmt->error;
} else {
echo 'success';
}
$stmt->close();
} else {
echo 'error:'.$mysqli->error;
}
$mysqli->close();
更新
我添加了屏幕截图,我的时间列的样子。可以吗?