I'm using:
Windows Server 2003 width IIS.
PHP 5..2.1
SQL Server 2000
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.
Here are the tables and their content:
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)
And here is the PHP code:
<?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();
?>
Error message:
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