我正在尝试将日期时间插入到MSSQL数据库中,但是我没有得到它,我总是收到错误。 我已经在互联网上阅读过,没有人遇到过这样的问题,它有什么用呢?
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require "init.php";
$name = "20498090R";
$entSal = "1";
$ts = "2017-04-19 13:36:43";
$motivos = "";
$actividades = "";
$laobra = "PRY12345";
$newdate = date('Y-m-d H:i:s', strtotime($ts));
$pruebas = sqlsrv_num_rows($probar);
$comprobar = "SELECT * FROM [dbo].[Empleados] WHERE NIF ='".$name."';";
$probar = sqlsrv_query($con, $comprobar);
if(sqlsrv_has_rows($probar) === false){
echo 'Usuario no registrado en el sistema';
}else{
$sql = "INSERT INTO [dbo].[Fichajes] ( Empleado, Obra, Hora, Entrada,
Motivo, Actividad) VALUES ('".$name."','".$laobra."','".$newdate."','".$entSal."','".$motivos."','".$actividades."');";
if(!sqlsrv_query($con, $sql)){
die( print_r( sqlsrv_errors(), true));
}
}
?>
错误MSJ:
Array ( [0] => Array ( [0] => 22007 [SQLSTATE] => 22007 [1] => 242 [code] => 242 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Converting the varchar data type to datetime produced a value out of range. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]La conversi�n del tipo de datos varchar en datetime produjo un valor fuera de intervalo. ) [1] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 3621 [code] => 3621 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Se termin� la instrucci�n. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Se termin� la instrucci�n. ) )
如果我不执行$ newdate变量我遇到同样的问题