Skip to content

Commit 5fbc947

Browse files
andrewbesskaryna-t
authored andcommitted
Fixed PDO statement with tests for compatibility with PHP >= 8.0
1 parent b194914 commit 5fbc947

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/internal/Magento/Framework/DB/Statement/Pdo/Mysql.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
class Mysql extends \Zend_Db_Statement_Pdo
1616
{
17-
1817
/**
1918
* Executes statement with binding values to it. Allows transferring specific options to DB driver.
2019
*
@@ -40,7 +39,7 @@ public function _executeWithBinding(array $params)
4039
// Separate array with values, as they are bound by reference
4140
foreach ($params as $name => $param) {
4241
$dataType = \PDO::PARAM_STR;
43-
$length = null;
42+
$length = is_string($param) ? strlen($param) : 0;
4443
$driverOptions = null;
4544

4645
if ($param instanceof Parameter) {
@@ -88,7 +87,7 @@ public function _execute(array $params = null)
8887
return $this->_executeWithBinding($params);
8988
} else {
9089
return $this->tryExecute(function () use ($params) {
91-
return $params !== null ? $this->_stmt->execute($params) : $this->_stmt->execute();
90+
return !empty($params) ? $this->_stmt->execute($params) : $this->_stmt->execute();
9291
});
9392
}
9493
}

lib/internal/Magento/Framework/DB/Test/Unit/DB/Statement/MysqlTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function testExecuteWhenParamsAsParameterObject()
114114
{
115115
$param1 = $this->createMock(Parameter::class);
116116
$param1Value = 'SomeValue';
117-
$param1DataType = 'dataType';
118-
$param1Length = '9';
117+
$param1DataType = \PDO::PARAM_STR;
118+
$param1Length = 9;
119119
$param1DriverOptions = 'some driver options';
120120
$param1->expects($this->once())
121121
->method('getIsBlob')
@@ -145,7 +145,7 @@ public function testExecuteWhenParamsAsParameterObject()
145145
->method('bindParam')
146146
->withConsecutive(
147147
[':param1', $param1Value, $param1DataType, $param1Length, $param1DriverOptions],
148-
[':param2', 'value2', \PDO::PARAM_STR, null, null]
148+
[':param2', 'value2', \PDO::PARAM_STR, 6, null]
149149
);
150150
$this->pdoStatementMock->expects($this->once())
151151
->method('execute');

0 commit comments

Comments
 (0)