|
|
Question : MySQL datetime insert into SQL Server datetime using PHP
|
|
We have a MySQL v5 database that sits behind a website on a web server.
A PHP script is used to take records and insert them into an SQL Server 2000 database that resides on another server. The PHP script uses the free TDS driver.
We are having a problem with one field which is a datetime field. The datetime field does not insert into the SQL Server database correctly, even though the corresponding SQL Server field is also datetime.
We get NULL inserts for this field.
Can you help? Thanks.
|
Answer : MySQL datetime insert into SQL Server datetime using PHP
|
|
>This results in a new row with NULL in the datetimecompleted column. I cannot believe that, unless you have a trigger on the table..
in MySQL, if the value is not in the correct format or an out-of-range value, it will silently put 0000-00-00 instead. in MS SQL, if the value is not in the correct format or an out-of-range value, it will raise an error (and the insert will fail/rollback).
note: INSERT INTO thetable datetimecompleted values('29/02/2008 15:34:23') uses implicit data type conversion, which is BAD behaviour.
better use this explicit data type conversion method: INSERT INTO thetable (datetimecompleted) SELECT CONVERT(datetime, '29/02/2008 15:34:23', 103)
|
|
|
|
|