正确格式化的MySQL日期insert语句返回全0 [英] Properly formatted MySQL date insert statement returns all 0's

查看:391
本文介绍了正确格式化的MySQL日期insert语句返回全0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个解析HTML页面的PHP脚本,创建一个MySQL查询,并将解析的数据插入到MySQL表中。一切正常,除了一件事:日期字段。当PHP运行MySQL语句时,表中的日期读取0000-00-00。如果我回应MySQL查询,则会产生以下结果:

I've created a PHP script that parses an HTML page, creates a MySQL query, and inserts the parsed data into a MySQL table. Everything works fine, except for one thing : the date field. When PHP runs the MySQL statement, the dates in the table read 0000-00-00 . If I echo the MySQL query, it results in the following :

INSERT INTO dispatch_table (dispatch_date, dispatch_time, dispatch1, dispatch2, dispatch3, dispatch4, dispatch5, dispatch6, dispatch7, dispatch8, dispatch9, dispatch10, dispatch11, dispatch12, dispatch13, dispatch14, dispatch15, dispatch16)VALUES ('2010-02-02', '10:46:17', '31.90' , '32.15','32.24','32.39','33.46','35.18','39.33','39.39','40.92','41.79','41.82','44.35','45.47','46.89','47.13','67.59');

如果我将该语句复制并粘贴到MySQL表中,它会插入日期,但是PHP trys插入它,我被赋予全0。 dispatch_date字段是MySQL中的date字段。在使用PHP代码插入日期之前,插入的日期将转换为字符串(我认为这可能会解决我的问题)。任何人都可以给我任何见解吗?

If I copy and paste the statement into the MySQL table, it inserts the date just fine, but when PHP trys to insert it, I am given all 0's. The dispatch_date field is a "date" field in MySQL. Before inserting the dates with the PHP code, the date to insert is converted to a string (I thought this might solve my problem). Can anyone give me any insight on this?

推荐答案

从tizag.com

From tizag.com

当您输入
以外的日期时,为
给定日期类型的范围或格式错误,MySQL通常只会
输入所有
零的默认值。

When you enter dates that are out of the range or in the wrong format for a given date type, MySQL will often just enter in the default value of all zeros.

您正在以错误的格式存储它们。

You are storing them in the wrong format.

这篇关于正确格式化的MySQL日期insert语句返回全0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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