Bug #57655 [Opn->Dup]: PDO_DBLIB prepare statements quoting integers
| From: | adambaratz@php.net | Date: | Tue, 31 Oct 2017 22:01:34 +0000 |
| Subject: | Bug #57655 [Opn->Dup]: PDO_DBLIB prepare statements quoting integers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212395@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=57655&edit=1
ID: 57655
Updated by: adambaratz@php.net
Reported by: nkgrant at gmail dot com
Summary: PDO_DBLIB prepare statements quoting integers
-Status: Open
+Status: Duplicate
Type: Bug
Package: PDO DBlib
Operating System: Linux (Debian Sarge)
PHP Version: 5.2.1
Block user comment: N
Private report: N
New Comment:
See #73234.
Previous Comments:
------------------------------------------------------------------------
[2014-10-25 04:36:47] ssufficool@php.net
PECL module is not maintained. Will try to fix in master.
This only affects Sybase ASE as it does not have the same implicit conversions supported by MS SQL
Server.
Binding variables according to ZVAL type or specific binding type may result in BC breakage.
------------------------------------------------------------------------
[2014-10-23 03:49:31] ssufficool@php.net
Works in trunk with SQL Server 2008.
require("php_pdo_login.php");
$db = new PDO($dsn,$user,$pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT x from (select cast(1 as int) as x) as tab where x = ?";
$sth = $db->prepare($sql);
$sth->execute(array(1));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)){
print_r($row);
}
------------------------------------------------------------------------
[2014-10-21 04:17:16] ssufficool@php.net
All PDO_DBLIB binds are done as strings. To quote one of the PDO authors: "...strings give the
greatest fidelity...". There is no formal specification for how PDO *should* bind PHP zvals to
SQL Variables. This may change in the future.
The workaround would be to bind:
:myVar
as
cast(:myVar as int)
------------------------------------------------------------------------
[2009-08-17 13:01:05] 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()
------------------------------------------------------------------------
[2007-10-10 11:14:06] richardtector at thekeelecentre dot com
bindParam() should allow you to force it to handle it as an integer.
I must admit, I find it frustrating that you can't simply specify the parameter types during
the prepare as in DB/MDB2 where you just pass an array of types: array('integer',
'boolean') etc.
Hope that helps.
Richard
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=57655
--
Edit this bug report at https://bugs.php.net/bug.php?id=57655&edit=1