使用PHP将DateTime插入SQL Server [英] Insert DateTime into SQL Server Using PHP

查看:89
本文介绍了使用PHP将DateTime插入SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP将datetime值插入SQL数据库。

I'm trying to insert a datetime value into my SQL database using PHP.

这是我的代码:

$time= date('Y-m-d H:i:s.u');

$ordersquery= "INSERT INTO Orders (customerID, orderDate) VALUES ('{$phonenumber}', '{$time}')";
echo $ordersquery."\n";

每当我尝试执行代码时,都无法将信息输入读取的数据库中:

Whenever I try to execute the code, there is a failure to enter the information into the database that reads:


插入订单(customerID,orderDate)值('((444)849-7592',
'2015-05 -10 12:03:28.000000')

INSERT INTO Orders (customerID, orderDate) VALUES ('(444) 849-7592', '2015-05-10 12:03:28.000000')

布尔值错误

转换日期和/或时间时转换失败

Conversion failed when converting date and/or time from character string.

null

我也尝试过使用CURRENT_TIMESTAMP和ISO-8601格式。

推荐答案

请尝试以下格式:

$time= date('Y-m-d H:i:s');

要插入 日期时间 应为 YYYY-MM-DD HH:MM:SS格式。支持的范围是 1000-01-01 00:00:00到 9999-12-31 23:59:59。

The value to be inserted in Datetime should be in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

这篇关于使用PHP将DateTime插入SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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