Consider the following table:
CREATE TABLE foo (a VARCHAR(8), b VARCHAR(20))
Then consider the following prepared statement:
SELECT count(*) FROM foo WHERE a LIKE ?
Finally, consider the following PHP lines:
$stmt = odbc_prepare($dsn, $query); // Where $query is the above query
$filter = "%12345678%"; // Note: two wildcards and 8 real characters
odbc_execute($stmt, array($filter));
With PHP 5.3.13 on Windows x86 (as part of the WAMP package), and both the Microsoft SQL Server ODBC driver version 06.01.7601 and Microsoft SQL Server Native Client version 10.50.4000, the odbc_execute fails, generating a "String data, right truncation" error.
If, instead, I substitute the filter string directly into the query, like so:
SELECT count(*) FROM foo WHERE a LIKE '%12345678%'
of course it works just fine, since LIKE isn't ever supposed to lead to that error.
Is this something I'm getting wrong about prepared statements, or a bug in either PHP or the SQL Server driver?
%123456..%so make the filter like$filter = "'%12345678%'";- Professor Abronsiusodbc_executestill returnsfalse, but now bothodbc_error(sqlstate) andodbc_errormsgare both empty. :-( - Brian A. Henning