Project

General

Profile

Actions

Bug #65941

closed

TYPO3\CMS\Core\Database\PreparedStatement::execute() calls mysqli_stmt::bind_param() with zero parameters to bind

Added by Daniel Neugebauer over 9 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2015-03-23
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.5
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:

Description

When querying a PreparedStatement without any arguments (implicitely or explicitely), such as by

$stmt = $GLOBALS['TYPO3_DB']->prepare_SELECTquery('myColumn', 'myTable', ''); // select, from, where
$stmt->execute(array());

the following PHP warning will be logged:

PHP Warning:  Wrong parameter count for mysqli_stmt::bind_param() in .../typo3_src-6.2.11/typo3/sysext/core/Classes/Database/PreparedStatement.php on line 354

The offending lines are:

   346                  // ->bind_param requires second up to last arguments as references
   347                  $bindParamArguments = array();
   348                  $bindParamArguments[] = $combinedTypes;
   349                  $numberOfExtraParamArguments = count($values);
   350                  for ($i = 0; $i < $numberOfExtraParamArguments; $i++) {
   351                          $bindParamArguments[] = &$values[$i];
   352                  }
   353
   354                  call_user_func_array(array($this->statement, 'bind_param'), $bindParamArguments);

$combinedTypes is a string assembled earlier in execute() to contain all parameter's data types. If no parameters have been passed, $combinedTypes is an empty string and (on line 354) $bindParamArguments therefore reads:

Array
(
    [0] => 
)

This appears to get mapped to an unnecessary call of PHP's mysqli_stmt::bind_param('') which should causes the logged warning.

A patch which encloses lines 350-354 in a check for $numberOfExtraParamArguments > 0 has been attached to this issue.


Files

t3-PreparedStatement-execute-zero-parameters.patch (1.02 KB) t3-PreparedStatement-execute-zero-parameters.patch added check for zero arguments to avoid unnecessary call Daniel Neugebauer, 2015-03-23 16:13
Actions #1

Updated by Gerrit Code Review over 9 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/38097

Actions #2

Updated by Mathias Schreiber over 9 years ago

  • Sprint Focus set to On Location Sprint
Actions #3

Updated by Gerrit Code Review over 9 years ago

Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/38386

Actions #4

Updated by Andreas Fernandez over 9 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #5

Updated by Anja Leichsenring almost 9 years ago

  • Sprint Focus deleted (On Location Sprint)
Actions #6

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF