php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46387 Results are modified when passed back to the server
Submitted: 2008-10-25 20:15 UTC Modified: 2016-10-15 23:13 UTC
From: domze dot sa at gmail dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.2.6 OS: FreeBSD 7
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:
23 + 12 = ?
Subscribe to this entry?

 
 [2008-10-25 20:15 UTC] domze dot sa at gmail dot com
Description:
------------
I have a query here that gives the right results in SQL Management
Studio but wrong results in PHP (using mssql libraries under FreeBSD
using FreeTDS)

The query is as follow:
SELECT ROW_NUMBER() OVER (ORDER BY count DESC), s.*
FROM (
        SELECT ROW_NUMBER() OVER (ORDER BY t.field1), t.blah, ....,
        (SELECT COUNT(field2) FROM x WHERE x.fieldx=t.fieldx) AS count
        FROM table t
        WHERE CONTAINS(t.field3,'"some stuff"')
) AS s

In this query, in management studio the results are the desired
results
however in PHP, the field count is like incremented and doesn't give
the right results..

I'm using the following in a CTE because I need double ordering. (that
is ordering on field1 and then ordering on count)

Using freetds-msdblib-0.64_2 and mssql extensions

Wrapping this query in a stored procedures gives back the proper results.

Reproduce code:
---------------
<?php
$query = "WITH CTE AS (
							SELECT ROW_NUMBER() OVER (ORDER BY count DESC) rowNumber, s.*
							FROM (
											SELECT ROW_NUMBER() OVER (ORDER BY t.field1) rowNumber2, t.blah,
											(SELECT COUNT(field2) FROM x WHERE x.fieldx=t.fieldx) AS count
											FROM table t
											WHERE CONTAINS(t.field3,'"some stuff"')
						) AS s
					)
					SELECT TOP 30 * FROM [CTE] WHERE rowNumber>=1";
$ressource = mssql_query($query);
while ($row = _fetch_array($ressource)) {
	echo "<pre>"; print_r($row); echo "</pre>";
}
?>

Expected result:
----------------
management studio:
count for many records go from 1 1 1 0 0 0 0 ...

Actual result:
--------------
count for many records go from 3 3 3 2 2 1 1 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-15 23:13 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:13 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: Sun Jun 16 18:01:30 2024 UTC