Issue Bug Closed

#76248Backend LiveSearch "Invalid database result" entries in error-log if results are empty

M. Dartsch 05/20/16, 15:58 updated 10/02/18, 11:13

Description

Typo3 7.6.7 running with PHP 5.6 and MariaDB 10.1

Backend LiveSearch generates a lot of warnings in the servers error-log if results are empty:

core: Invalid database result detected: function TYPO3\\CMS\\Core\\Database\\DatabaseConnection->sql_num_rows called from file /sysext/backend/Classes/Search/LiveSearch/LiveSearch.php in line 205

JSON-Dump of the Object which triggers these warnings:

{"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null}

The warning comes from within the function getRecordArray() in /sysext/backend/Classes/Search/LiveSearch/LiveSearch.php

I fixed it for me adding an additional check for $result->num_rows > 0

Changes marked with “fix”:

        $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
        if( $result->num_rows > 0 ) {  // fix
            $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
            while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                $title = 'id=' . $row['uid'] . ', pid=' . $row['pid'];
                $collect[] = array(
                    'id' => $tableName . ':' . $row['uid'],
                    'pageId' => $tableName === 'pages' ? $row['uid'] : $row['pid'],
                    'typeLabel' =>  htmlspecialchars($this->getTitleOfCurrentRecordType($tableName)),
                    'iconHTML' => '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForRecord($tableName, $row, Icon::SIZE_SMALL)->render() . '</span>',
                    'title' => htmlspecialchars(BackendUtility::getRecordTitle($tableName, $row)),
                    'editLink' => htmlspecialchars($this->getEditLink($tableName, $row))
                );
                $isFirst = false;
            }
            $GLOBALS['TYPO3_DB']->sql_free_result($result);
        }  // end fix
        return $collect;

Reviews 2