There is a column url(nvarchar(200), not null)
<?php
//
$pdo = new PDO('odbc:mssql', 'xxx', 'yyy');
$pdo->setAttribute(PDO::ATTR_PERSISTENT, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
// plain sql query: WORKS FINE!
$sth = $pdo->prepare("SELECT COUNT(*) FROM pagina WHERE url = '/webito'");
$sth->execute();
// using bindValue: ERROR!
$sth = $pdo->prepare("SELECT COUNT(*) FROM pagina WHERE url = :unique_value");
$sth->execute(array('unique_value' => '/webito'));
Returning error:
Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 402 [FreeTDS][SQL Server]The data types nvarchar and text are incompatible in the equal to operator. (SQLExecute[402] at /builddir/build/BUILD/php-5.4.15/ext/pdo_odbc/odbc_stmt.c:254) in /root/php/test.php on line 13
Is this a bug?
Using: php 5.4.15, unixodbc 2.2.14, freetds 0.91, sql-server-2012, centos-x64 6.4
Update:
Seems to be a bug. I found this patch, but works only with ODBC Driver 11 for SQL Server (I tried with FreeTDS, no luck). I managed to install PHP from source with this patch applied and changed from FreeTDS to ODBC Driver 11 for SQL Server; now is working.
- php 5.4.15
- unixODBC 2.3.0
- ODBC Driver 11 for SQL Server
- sql-server-2012
- centos-x64 6.4