0

尝试将日期作为字符串从数组插入到 SQL Server 2008 并收到此错误

Array ( [0] => Array ( [0] => 22007 [SQLSTATE] => 22007 [1] => 241 [code] => 241 [2] => [Microsoft][SQL Server Native Client 11.0][SQL服务器]从字符串转换日期和/或时间时转换失败。[消息] => [Microsoft][SQL Server Native Client 11.0][SQL Server]从字符串转换日期和/或时间时转换失败。))

插入数组是这样的

$data = array(
    'date' => '2012-10-12',
    'time' => '10:37:10'
);

日期字段数据类型日期时间字段数据类型时间(7)

$sql = "INSERT INTO test (p_date, p_time) VALUES (?, ?)";

$stmt = sqlsrv_prepare($conn, $sql, array(&$data['date'], &$data['time']));

if( sqlsrv_execute($stmt) === false) 
{
    die( print_r( sqlsrv_errors(), true));
}
4

0 回答 0