Edit report at https://bugs.php.net/bug.php?id=57655&edit=1
ID: 57655 Updated by: [email protected] Reported by: nkgrant at gmail dot com Summary: PDO_DBLIB prepare statements quoting integers -Status: Open +Status: Assigned Type: Bug Package: PECL Operating System: Linux (Debian Sarge) PHP Version: 5.2.1 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2014-10-25 04:36:47] [email protected] 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] [email protected] 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] [email protected] 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 -- PECL development discussion Mailing List (http://pecl.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
