php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57716 PDO_ODBC: bindParam reports int as varchar
Submitted: 2007-06-22 10:39 UTC Modified: 2014-01-01 12:42 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: cshaulis at bear dot com Assigned:
Status: Open Package: PDO ODBC
PHP Version: 5.2.1 OS: Windows
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-06-22 10:39 UTC] cshaulis at bear dot com
Description:
------------
I am using the ODBC driver under Windows to connect PHP to a Sybase database. When using bindParam to bind variables to a prepared statement I receive the following error:

22018,257,[INTERSOLV][ODBC SQL Server driver][SQL Server]Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed.  Use the CONVERT function to run this query.
 (SQLExecute[257] at ext\pdo_odbc\odbc_stmt.c:133),22018

However, I have specified that the variable is an integer and I have confirmed the variable actually contains a number. I have the same result when I don't explicitly declare the type. The database_name..table_name specifier in the SQL below is Sybase specific, but I'm including it in case it might alter the behavior of the prepare command.


Reproduce code:
---------------
create table test (
  a int not null,
  b int not null,
  c varchar not null,
  d varchar not null
)

$sthd = $dbhd->prepare("INSERT INTO test_db..test_tbl (c, d, a, b) VALUES (?, ?, ?, ?)");
$sthd->bindParam(1, $cvar, PDO::PARAM_STR);
$sthd->bindParam(2, $dvar, PDO::PARAM_STR);
$sthd->bindParam(3, $avar, PDO::PARAM_INT);
$sthd->bindParam(4, $bvar, PDO::PARAM_INT);
$avar = 123;
$bvar = 123;
$cvar = "test";
$dvar = "test";
if (!$sthd->execute()) {
   print(implode(',', $sthd->errorInfo()) . "\n");
}


Expected result:
----------------
I expect there to be no output and no error condition set. Using the same code to insert into an SQLite database using PDO works as expected.


Actual result:
--------------
I receive the error message above.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-17 13:01 UTC] a at a dot com
Unfortunately, it does not work even with bindParam(..., PDO::PARAM_INT). 

I've tried many (all?) potential solutions, but did not found any, except using convert()
 [2013-06-12 03:53 UTC] ssufficool@php.net
-Summary: bindParam reports int as varchar +Summary: PDO_ODBC: bindParam reports int as varchar -Package: PDO_ODBC +Package: *General Issues
 [2013-12-05 19:36 UTC] mike@php.net
-Package: *General Issues +Package: PDO related
 [2014-01-01 12:42 UTC] felipe@php.net
-Package: PDO related +Package: PDO ODBC
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC