php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61777 Cannot bind parameters with pdo_odbc and SQL Server Native Client 11.0
Submitted: 2012-04-19 18:45 UTC Modified: 2014-12-30 10:41 UTC
Votes:65
Avg. Score:4.9 ± 0.3
Reproduced:63 of 64 (98.4%)
Same Version:27 (42.9%)
Same OS:15 (23.8%)
From: frozen at frozen-solid dot net Assigned:
Status: No Feedback Package: PDO ODBC
PHP Version: 5.3.10 OS: Ubuntu 12.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-04-19 18:45 UTC] frozen at frozen-solid dot net
Description:
------------
When trying to bind parameters to a prepared statement, bindValue() and 
bindParam() both return false with the error code HY004, [SQL Server Native Client 
11.0]Invalid SQL data type (SQLBindParameter[0] at /build/buildd/php5-
5.3.10/ext/pdo_odbc/odbc_stmt.c:379)

It does not matter whether you pass in PDO::PARAM_STR or PARAM_INT or no data type 
specification, the error is the same every time.

Using parameters with odbc_connect() and odbc_prepare() work as expected, so the 
issue is directly related to PDO, not to ODBC or Microsoft's driver.

Test script:
---------------
$db = new PDO('odbc:sqltest', 'wwwuser', 'btsb');

$strSql = 'select top 10 * from oltmaster where titleno = :no';

$q = $db->prepare($strSql);

var_dump($q->bindValue(':no', '029803'));
var_dump($q->errorInfo());

Expected result:
----------------
boolean true

array
  0 => string '' (length=0)
  1 => int 0
  2 => string ' ((null)[0] at (null):0)' (length=24)
  3 => string '' (length=0)

Actual result:
--------------
boolean false

array
  0 => string 'HY004' (length=5)
  1 => int 0
  2 => string '[Microsoft][SQL Server Native Client 11.0]Invalid SQL data type 
(SQLBindParameter[0] at /build/buildd/php5-5.3.10/ext/pdo_odbc/odbc_stmt.c:379)' 
(length=143)
  3 => string 'HY004' (length=5)


Patches

odbc.patch (last revision 2013-01-15 17:03 UTC by kraven at kraven dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-15 18:59 UTC] burnhamrobertp at gmail dot com
Debian Squeeze 2.6.32-5-amd64
PHP 5.3.3 (also reproducible under PHP 5.4.0-3)

The test case and error information are exactly the same.
 [2012-10-18 17:05 UTC] kraven at kraven dot org
I believe this is related to the SQLLEN.  PHP bug 5044 has a patch.

MS bug here where developer says its SQLLEN:
http://connect.microsoft.com/SQLServer/feedback/details/737751/cannot-bind-
parameters-with-php-pdo-odbc-and-sql-native-client-11-0

I applied the patches in bug 50444 and now it's working for me.
 [2013-01-30 00:43 UTC] paul dot posts at gmail dot com
Can confirm that patches in bug 50444 correct this issue for me as well.
 [2013-04-04 20:36 UTC] me at andrewkehrig dot com
I can verify this bug still occurs on php 5.3.19 and php 5.4.6 as well.

php 5.3.19 running on Windows experiences a slightly different version of this problem when talking to SQL Server via ODBC: bound parameters work, as long as you're not comparing them directly to date datatype columns (date, timestamp, etc) - if you are, you have to cast them manually from varchar to date, or if you're using a stored procedure with input parameters you have to set any date input parameters to varchar and allow the server to infer the datatype conversion when comparing the input parameter(a varchar holding a date, timestamp, etc) to an actual date,timestamp,etc column.
 [2014-01-01 12:38 UTC] felipe@php.net
-Package: PDO related +Package: PDO ODBC
 [2014-03-17 13:08 UTC] donald dot sipe at gmail dot com
Are there plans to address this issue in an upcoming php release?  

This is a serious issue for those of us that would like to use the native MS SQL Server driver since that is the best "Enterprise" solution for connecting to SQL Server on Linux.
 [2014-04-20 23:57 UTC] stas@php.net
-Status: Open +Status: Feedback
 [2014-04-20 23:57 UTC] stas@php.net
Please try using this snapshot:

  http://snaps.php.net/php-trunk-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Fix for bug #50444 checked in, please see if it also fixes this issue.
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2015-02-02 15:54 UTC] frozen at frozen-solid dot net
Problem still occurs  in PHP 5.4.36 on Debian
 [2015-04-29 12:54 UTC] omar dot piani at gmail dot com
I have same problem, binding booleans as true and false, works well using 0 and 1.

Regards
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC