php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41039 SQL join with bound parameter fails with 'text, ntext, image' error.
Submitted: 2007-04-10 15:08 UTC Modified: 2007-04-10 21:35 UTC
From: emil at troxy dot net Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.1 OS: Windows Server 2003
Private report: No CVE-ID: None
 [2007-04-10 15:08 UTC] emil at troxy dot net
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-10 15:20 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2007-04-10 21:35 UTC] emil at troxy dot net
I'm sorry if my bug submission doesn't belong here.
Anyway, I was able to reproduce this problem using a simple subquery aswell.
So it seems like this is a resubmission of bug #36561.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 12:01:28 2024 UTC