Home > Database > Mysql Tutorial > body text

mysql中时间日期 datetime字段保存日期出现0000-00-00

WBOY
Release: 2016-06-07 17:52:11
Original
2198 people have browsed it

如果大家注意一下datetime日期格式类型的话就应该可以不要问了,datetime日期必须是 2012-01-01 10:10:10 这种,否则就有可能出来0000-00-00

正确的php sql语句写法应该是: 

 

 代码如下 复制代码
$sql = "insert into table(datetime) values('".date("Y-m-d h:i:s",time())."')"; //datetime字段的类型为“datetime”,


注意后面要插入的数据是字符串要加“单引号”。
这样就没错了,时间日期类型插入数据库之前要格式化,否则就出现插入的全是0000-00-00的问题。

个人建义,大家保存时间时最好使用int类型保存time()生成的日期这样操作会更方便。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!