From:             christian dot ehlscheid at gmx dot de
Operating system: Windows XP
PHP version:      5.2.9
PHP Bug Type:     PDO related
Bug description:  ODBC and bound parameters

Description:
------------
Hi,

this is a reopening of Bug # 36561 - http://bugs.php.net/36561

After this comment:
"This appears to be a bug with prepared statements in the underlying
microsoft client driver implementation..."
the bug was marked as bogus.

I would call it a limitation, a well documented one
(http://msdn.microsoft.com/en-us/library/ms130945.aspx), and I think it is
a PDO ODBC bug.

I had a look at the source code of the PDO ODBC driver and this issue can
easily be fixed, and it should be in my opinion.

Here's the code that should be altered:
function "odbc_stmt_param_hook" in the file "odbc_stmt.c"

"rc = SQLDescribeParam(S->stmt, param->paramno+1, 
&sqltype, &precision, &scale, &nullable);

if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
{
/* MS Access, for instance, doesn't support SQLDescribeParam,
 * so we need to guess */
                sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
SQL_LONGVARBINARY : SQL_LONGVARCHAR;

..."

The code tries to get the datatype of the bound parameter with the call to
the ODBC API function SQLDescribeParam, which fails under MSSQL/MS Access
and other databases.

Then it sets the sqltype variable (which holds the ODBC datatype under
which the parameter is later bound) to SQL_LONGVARCHAR or SQL_LONGVARBINARY
.. 

the comment in the code tells it all .. "so we need to guess" .. 

the solution is quite simple -> don't guess. 

The correct ODBC datatype can be deduced from the type of the bound PHP
variable, and if the developer specified a concrete type in the bindParam
call (e.g. $oStatement->bindParam(':TestID', $iTestID,PDO::PARAM_INT ); )
the whole call to SQLDescribeParam is not neccessary and the PDO type
specified should be directly mapped to the equivalent ODBC datatype.

Now the problematic code and the solution is known and I hope someone will
fix it.

Christian

Reproduce code:
---------------
MSSQL:
CREATE TABLE zTest_TBL (
        TestID int NULL 
) 
INSERT INTO zTest_TBL (TestID) Values (1)

PHP:
<?
$iTestID=1;
$oConnection = new PDO($sDSN, $GLOBALS["sDatabase_Username"],
$GLOBALS["sDatabase_Password"]);
$oStatement = $oConnection->prepare('SELECT TestID FROM zTest_TBL WHERE
TestID IN (SELECT TestID FROM zTest_TBL WHERE TestID = :TestID)');
//$oStatement = $oConnection->prepare('SELECT TestID FROM zTest_TBL
WHERE TestID = :TestID AND TestID  IN (SELECT TestID FROM zTest_TBL
)');
$oStatement->bindParam(':TestID', $iTestID,PDO::PARAM_INT );
$oStatement->execute() or print_r($oStatement->errorInfo());
foreach($oStatement as $aRow) {
  print_r($aRow);
}
?>



-- 
Edit bug report at http://bugs.php.net/?id=48295&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48295&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48295&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48295&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48295&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48295&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48295&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48295&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48295&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48295&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48295&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48295&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48295&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48295&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48295&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48295&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48295&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48295&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48295&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48295&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48295&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48295&r=mysqlcfg

Reply via email to