From: emil at troxy dot net Operating system: Windows Server 2003 PHP version: 5.2.1 PHP Bug Type: PDO related Bug description: SQL join with bound parameter fails with 'text, ntext, image' error.
Description: ------------ I'm trying to do a simple SQL join using a prepared statement with a bound parameter as a part of the condition. The execution of the statement fails with an exception saying that I'm trying to do a compare on text, ntext or image data types, even though the tables don't contain these types. Reproduce code: --------------- CREATE TABLE [table1] ( [id] [int] NOT NULL ) ON [PRIMARY] CREATE TABLE [table2] ( [id] [int] NOT NULL ) ON [PRIMARY] INSERT INTO [table1] VALUES(1) INSERT INTO [table2] VALUES(1) <?php $dbh = new PDO('odbc:Driver={SQL Server}; Server=127.0.0.1; Uid=userid; Pwd=password; Database=database;'); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->prepare("SELECT t1.id, t2.id FROM table1 t1 INNER JOIN table2 t2 ON (t1.id = ?) AND (t2.id = 1)"); $stmt->bindValue(1, 1, PDO::PARAM_INT); $stmt->execute(); ?> Expected result: ---------------- The statement should execute without errors and return TRUE. Actual result: -------------- PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 306 [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)' in D:\Website\pdo.php:8 Stack trace: #0 D:\Website\pdo.php(8): PDOStatement->execute() #1 {main} thrown in D:\Website\pdo.php on line 8 -- Edit bug report at http://bugs.php.net/?id=41039&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41039&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41039&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41039&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41039&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41039&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41039&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41039&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41039&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41039&r=support Expected behavior: http://bugs.php.net/fix.php?id=41039&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41039&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41039&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41039&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41039&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41039&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41039&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41039&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41039&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41039&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41039&r=mysqlcfg