|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-04-10 15:20 UTC] tony2001@php.net
[2007-04-10 21:35 UTC] emil at troxy dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
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