Doc #78945 [NEW]: Different behavior PARAM_INT on string in 7.0 and 7.2
From: shol_ at hotmail dot com
Operating system: CentOS
PHP version: 7.2.25
Package: PDO MySQL
Bug Type: Documentation Problem
Bug description:Different behavior PARAM_INT on string in 7.0 and 7.2
Description:
------------
The main 'problem' I have is undocument change of behavior in pdo's
bindParam() when binding a string as integer.
In php 7.0 I think it's silently binded as string because the queries
return the expected result. In 7.2.25 and 7.3 (I didn't test 7.1) no
warnings or exceptions are raised, but all rows are returned.
I want this change of behavior be documented (please correct me if I'm
wrong, I can't find it here as bug or in the upgrade/release notes).
And a nice to have would be a warning in the logfiles.
Test script:
---------------
$driver_options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8
COLLATE UTF8_unicode_ci', PDO::MYSQL_ATTR_LOCAL_INFILE => 1);
$oDb = new LoggedPDO('mysqli:host=localhost;dbname=DATABASENAME',
'USERNAME', 'PASSWORD',$driver_options);
$oDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oDb->exec('
CREATE TABLE test_parambinding (
id int(10) NOT NULL,
name varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO test_parambinding (id, name) VALUES
(1, "one"),
(2, "two");
ALTER TABLE test_parambinding
ADD PRIMARY KEY (id);
ALTER TABLE test_parambinding
MODIFY id int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
COMMIT;
');
$oStmt = $oDb->prepare('SELECT * FROM test_parambinding WHERE name
=
:name');
$name = 'one';
echo 'Bind string $name as PDO::PARAM_INT';
echo PHP_EOL;
$oStmt->bindParam(':name', $name, PDO::PARAM_INT);
$oStmt->execute();
$aResults = $oStmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($aResults);
Expected result:
----------------
Not really 'expecting' this, but this is how it worked in php <= 7.0.
The query fetches one (the expected) row:
array(1) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["name"]=>
string(3) "one"
}
}
Maybe it would be best if PDO generates a warning or throws an exception
(string bound as integer?).
Actual result:
--------------
PHP 7.2 and 7.3 fetches all rows (in this example case, both rows).
--
Edit bug report at https://bugs.php.net/bug.php?id=78945&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78945&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78945&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78945&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78945&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78945&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78945&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78945&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78945&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78945&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78945&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78945&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78945&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78945&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78945&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78945&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78945&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78945&r=mysqlcfg
Thread (4 messages)
- shol_ at hotmail dot com