Bug #48295 [Opn->Dup]: ODBC and bound parameters
Edit report at https://bugs.php.net/bug.php?id=48295&edit=1
ID: 48295
Updated by: cmb@php.net
Reported by: christian dot ehlscheid at gmx dot de
Summary: ODBC and bound parameters
-Status: Open
+Status: Duplicate
Type: Bug
Package: PDO ODBC
Operating System: Windows XP
PHP Version: 5.2.9
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #44643.
Previous Comments:
------------------------------------------------------------------------
[2009-05-15 13:18:23] christian dot ehlscheid at gmx dot de
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 this bug report at https://bugs.php.net/bug.php?id=48295&edit=1
Thread (2 messages)