doupan6648 2014-05-14 09:42
浏览 32
已采纳

来自MS-SQL的SmallDateTime无法在PHP中运行

I have a strange problem that when using PHP to connect to a MSSQL database using freetds the query returns no data.

I have two SQL queries:

SELECT TOP 100 *
FROM [TBL_Contact] AS C
LEFT JOIN [TBL_Address] AS A
    ON (C.[ContactID] = A.[ContactID])
;

and

SELECT TOP 100
    N.[NoteID],
    N.[NoteTypeID],
    N.[IsPrivate],
    CAST(N.[NoteText] AS TEXT) AS [NoteText],
    N.[ManageUserID],
    N.[DisplayDate],
    N.[CreateUserID],
    N.[CreateDateE],
    N.[EditUserID],
    N.[EditDate]
FROM [TBL_Note] AS N
LEFT JOIN [TBL_Contact_Note] AS C
    ON (C.[NoteID] = N.[NoteID])
;

When run directly on the MSSQL Server they both work as expected and return data. However when running them via PHP by wrapping them in a mssql_query() function call.

$result = mssql_query('
   SELECT TOP 100 *
   FROM [TBL_Contact] AS C
    LEFT JOIN [TBL_Address] AS A
        ON (C.[ContactID] = A.[ContactID])
    ;
');

$result1 = mssql_query('
    SELECT TOP 100
        N.[NoteID],
        N.[NoteTypeID],
        N.[IsPrivate],
        CAST(N.[NoteText] AS TEXT) AS [NoteText],
        N.[ManageUserID],
        N.[DisplayDate],
        N.[CreateUserID],
        N.[CreateDateE],
        N.[EditUserID],
        N.[EditDate]
    FROM [TBL_Note] AS N
    LEFT JOIN [TBL_Contact_Note] AS C
        ON (C.[NoteID] = N.[NoteID])
    ;
');

Then only the first one returns data.


I have experimented by removing fields from the query and have found that it is the smalldatetime field N.[DisplayDate] that is causing the issue. When I run the query with that field removed then the mssql_query() call works.

  • 写回答

1条回答 默认 最新

  • dongzaliang4492 2014-05-15 10:59
    关注

    Ok I've found out what the issue is there is a bug with PHP and the smalldatetime data type

    There is a fix for this which involves disabling the mssql.datetimeconvert setting in the php.ini file.

    The fix found on the web is to using ini_set to change the setting.

    ini_set('mssql.datetimeconvert', 0);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)