php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48908 Cannot query smalldatetime type columns
Submitted: 2009-07-13 19:54 UTC Modified: 2016-10-15 23:11 UTC
Votes:17
Avg. Score:4.3 ± 0.9
Reproduced:13 of 14 (92.9%)
Same Version:5 (38.5%)
Same OS:4 (30.8%)
From: aaron at aarondm dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.2.10 OS: ArchLinux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
11 + 7 = ?
Subscribe to this entry?

 
 [2009-07-13 19:54 UTC] aaron at aarondm dot com
Description:
------------
When trying to query a table, with a column whos type is 'smalldatetime', the code will result in a 500 Internal Error

Reproduce code:
---------------
Create table with the following columns

----------------------------------------
MY_TABLE
----------------------------------------
|(int) ID | (smalldatetime) MY_EXAMPLE |
----------------------------------------

Run:
$result = mssql_query("SELECT MY_EXAMPLE FROM MY_TABLE");

When you run that, you will get a:
500 Internal Server Error

On ArchLinux/Windows



Expected result:
----------------
No 500 Internal Server Error.

Should be able to query the database with no problems

Actual result:
--------------
500 Internal Server Error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-16 16:14 UTC] aaron at aarondm dot com
I have run the same query on Windows Server 2003 (Enterprise Edition) and this does not seem to be an issue. On windows it is able to fetch the column data with no problems.
 [2009-12-21 10:13 UTC] php at mike2k dot com
Always repeatable.

This is an issue for us as well. The previous comment is from a Windows user so they're probably able to leverage more native Windows MSSQL libraries...

PHP 5.2.11, on Linux, using FreeTDS on CentOS 5.3 (or 5.4, not sure) x86_64

The workaround is having to cast the column inside of the query. I will try to post an example workaround query when I grab one from the dev team.

Related Packages/versions of the driver, just in case:
freetds-devel-0.64-11.el5.centos
freetds-devel-0.64-6.el5
freetds-0.64-11.el5.centos
freetds-0.64-6.el5
unixODBC-2.2.11-7.1 (32 bit)
unixODBC-2.2.11-7.1 (64 bit)
unixODBC-devel-2.2.11-7.1 (32 bit)
unixODBC-devel-2.2.11-7.1 (64 bit)
 [2009-12-21 11:22 UTC] php at mike2k dot com
Sample query/workaround:

old: SELECT acct_itm.cre_dtm AS cre_dtm
new: SELECT CONVERT(varchar(10),acct_itm.cre_dtm,120) AS cre_dtm

Not the most ideal. Might be a bug in the FreeTDS driver and not something PHP can handle but has to pass upstream.
 [2010-01-07 12:36 UTC] undicizeri at gmail dot com
Same bug here.
I'm using Ubuntu with php 5.2.6 and debian with php 5.2.12.
 [2010-07-20 11:51 UTC] tom dot lawton at kondor dot co dot uk
PHP 5.2.4 / ubuntu 8.10LTS has this bug and is reproducable.

Suhosin patch reports canary mismatch if a query returns smalldatetime.

Apache does not trigger 500, nor does PHP report any error to the page - it dies silently.
 [2011-06-30 04:55 UTC] Fr33z3m4n at gmx dot net
Same Problem and is reproducable.

Debian 2.6.26-26lenny1
PHP Version 5.3.6-12
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
   with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
 [2011-09-14 17:40 UTC] me at abiusx dot com
As described in http://php.net/manual/es/function.mssql-query.php comments,

Adding
mssql.datetimeconvert = Off
in php.ini fixes the issue!
 [2012-02-18 19:10 UTC] blyxx86 at gmail dot com
Also get this in PHP Version 5.3.2-1ubuntu4.14.

Adding 
mssql.datetimeconvert = Off
to php.ini does allow it to work.
 [2016-10-15 23:11 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:11 UTC] kalle@php.net
With MSSQL being removed from PHP as of PHP7.0, and ext/mssql not having a maintainer, I'm gonna close this report as a Won't fix, until maybe one day it will find a new maintainer.

Alternatively you can use sqlsrv from Microsoft if you are on Windows, or pdo_dblib if you are on Unix.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 02:01:29 2024 UTC