每次在我的数据库中保存新条目时,我都会尝试知道时间和日期。所以我按如下方式设置列:
问题在于我只是将00:00:00作为日期/时间:
我用来更新数据库的代码是:
<?php
$lat = $_GET['lat'];
$lon = $_GET['lon'];
$fecha = $_GET['fecha'];
// Make a MySQL Connection
$db_database = "xxx";
$db_hostname = "xxx";
$db_username = "xxx";
$db_password = "xxx";
$enlace = mysql_connect($db_hostname, $db_username, $db_password);
if (!$enlace) {
die('No pudo conectarse: ' . mysql_error());
}
echo 'Conectado satisfactoriamente. <br>';
// mysql_close($enlace);
mysql_select_db('xxxxx') or die(mysql_error());
$q = "INSERT INTO `posicion` (`Hora`, `Latitud`, `Longitud`) VALUES
('$fecha', '$lat','$lon')";
//Run Query
$result = mysql_query($q) or die(mysql_error());
echo "Tamos redi";
?>
它有什么用?
非常感谢。
答案 0 :(得分:2)
考虑到Hora
的默认值为CURRENT_TIMESTAMP
,您可以依靠MySQL来填充它。
$q = "INSERT INTO `posicion` (`Hora`, `Latitud`, `Longitud`) VALUES
(NULL, '$lat','$lon')";
答案 1 :(得分:0)
尝试:
alter table <INSERT TABLENAME> modify <Hora> TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP;
和reffer: http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html