从PHP向MySql插入日期和时间值 [英] Inserting a Date and Time value to a MySql from PHP

查看:270
本文介绍了从PHP向MySql插入日期和时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我希望以与MySQL的DateTime格式兼容的格式发送到MySQL数据库,即:0000-00-00 00:00:00 ...

Hello i want to send to a MySQL data base a date and time in a format compatible with the mysql DateTime format, wich is: 0000-00-00 00:00:00 ...

我使用这个代码从PHP命令带来日期和时间:

Im using this code who brings the date and time from a PHP command:

   $insert = "INSERT INTO sms (ref, texto, fecha)
   VALUES ('".$_POST['usuario']."', '".$_POST['sms']."', '".date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000))."')";
   $add_member = mysql_query($insert);

我真的想这样做,但是使用MySQL命令,我的意思是使用日期和时间从mysql服务器。谢谢

I really want to do this but with a MySQL command, i mean, using the Date and Time from the mysql server. Thanks

推荐答案

插入记录时使用 NOW() INSERT INTO表(日期)VALUES(NOW())

对于您的代码:

$insert = "INSERT INTO sms (ref, texto, fecha)
VALUES ('".$_POST['usuario']."', '".$_POST['sms']."', NOW() )";
$add_member = mysql_query($insert);

这篇关于从PHP向MySql插入日期和时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆