#36561 [NoF->Opn]: PDO_ODBC/MSSQL does not work with bound params in subquery

From: Date: Thu, 24 May 2007 20:50:41 +0000
Subject: #36561 [NoF->Opn]: PDO_ODBC/MSSQL does not work with bound params in subquery
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-113005@lists.php.net to get a copy of this message
 ID:               36561
 User updated by:  travis at raybold dot com
 Reported By:      travis at raybold dot com
-Status:           No Feedback
+Status:           Open
 Bug Type:         PDO related
 Operating System: Windows XP
 PHP Version:      5.1.2
 New Comment:

Hey Wez, I never saw the feedback til I stumbled on it today, and
clearly have been able to work around this, but it does keep stopping
me.

It happens exactly the same if I omit the PDO::PARAM_INT as the final
parameter.

I am still using the branched version you gave me... I'd be happy to
test with the latest if you think it might be fixed there.

--Travis


Previous Comments:
------------------------------------------------------------------------

[2006-04-17 01:00:01] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------

[2006-04-09 07:57:01] wez@php.net

Try using:
$oStatement->bindParam(':TestID', $iTestID);
instead of:
$oStatement->bindParam(':TestID', $iTestID,PDO::PARAM_INT );
The latter is implicitly binding for output, which might be part of
your problem.

------------------------------------------------------------------------

[2006-02-28 17:10:09] travis at raybold dot com

Description:
------------
Connecting to a MSSQL database through PDO_ODBC, I prepare a statement
with a bound parameter inside of a subquery, and get a 42000 Syntax
Error when I execute it. 

The error indicates that it is trying to compare text. ntext or image
data, but the table consists solely of one integer field. Moving the
bound parameter outside of the subquery makes it work.

I am using PHP 5.1.2, MSSQL 2000, Windows XP, IIS6. 
Configure Line: cscript /nologo configure.js "--enable-snapshot-build"
"--with-gd=shared"



Reproduce code:
---------------
MSSQL:
CREATE TABLE zTest_TBL (
	TestID int NULL 
) 
INSERT INTO zTest_TBL (TestID) Values (1)

PHP:
<?
$iTestID=1;
$oConnection = new PDO($sDSN, $GLOBALS["sDatabase_Username"],
$GLOBALS["sDatabase_Password"]);
$oStatement = $oConnection->prepare('SELECT TestID FROM zTest_TBL WHERE
TestID IN (SELECT TestID FROM zTest_TBL WHERE TestID = :TestID)');
//$oStatement = $oConnection->prepare('SELECT TestID FROM zTest_TBL
WHERE TestID = :TestID AND TestID  IN (SELECT TestID FROM zTest_TBL
)');
$oStatement->bindParam(':TestID', $iTestID,PDO::PARAM_INT );
$oStatement->execute() or print_r($oStatement->errorInfo());
foreach($oStatement as $aRow) {
  print_r($aRow);
}
?>

Expected result:
----------------
Array ( [TestID] => 1 [0] => 1 ) 


Actual result:
--------------
Array ( [0] => 42000 [1] => 306 [2] => [Microsoft][ODBC SQL Server
Driver][SQL Server]The text, ntext, and image data types cannot be
compared or sorted, except when using IS NULL or LIKE operator.
(SQLExecute[306] at ext\pdo_odbc\odbc_stmt.c:133) [3] => 42000 )


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36561&edit=1


Thread (15 messages)

« previous php.bugs (#113005) next »