1

My logs have grown large full of entries of:

Notice: Undefined offset: 1 in lib/Zend/Db/Adapter/Abstract.php on line 814

My installation of magento is rather default, in that there isn't a vast amount of customisation. It is also up to date with the latest 1.9.3.10. Yet my logs will fill up with this notice.

To fix the issue, I have tried placing:

protected $_debug = true; protected $_logAllQueries = true; protected $_logCallStack = true;

In {Magento_root}/lib/Varien/Db/Adapter/mysqli.php

and enabling developer mode and display errors in index.php.

But, cannot locate cause of the notices. In fact this has no changing effect, nothing extra is logged neither.

Would anyone know a reason as to why this is happening?

For now, I have set the error_reporting directive at runtime to the following:

//Report all errors except E_NOTICE
 error_reporting(E_ALL & ~E_NOTICE);

UPDATE:

Trying to debug the issue further, I placed the following block on line 814:

        if (!isset($row[1]) || !isset($row[0])){
            Mage::log(PHP_EOL."row=>".Zend_Debug::dump($data[$row[0]], null, false).PHP_EOL, null, 'undefinedkeydebug.log');
            Mage::log(PHP_EOL."FETCH_NUM=>".Zend_Debug::dump($stmt->fetch(Zend_Db::FETCH_NUM), null, false).PHP_EOL, null, 'undefinedkeydebug.log');
            Mage::log(PHP_EOL."row0=>".Zend_Debug::dump($row[0], null, false).PHP_EOL, null, 'undefinedkeydebug.log');
            Mage::log(PHP_EOL."row1=>".Zend_Debug::dump($row[1], null, false).PHP_EOL, null, 'undefinedkeydebug.log');  
        }

Whereby, I am getting the following sort of output:

2018-10-19T03:50:02+00:00 DEBUG (7): 
datarow=>\<pre>NULL
\</pre>

2018-10-19T03:50:02+00:00 DEBUG (7): 
FETCH_NUM=>\<pre>array(1) {
  [0] =&gt; string(3) &quot;211&quot;
}
\</pre>

2018-10-19T03:50:02+00:00 DEBUG (7): 
row0=>\<pre>string(3) &quot;175&quot;
\</pre>

2018-10-19T03:50:02+00:00 DEBUG (7): 
row1=>\<pre>NULL
\</pre>

Now, analysing this I can see that '$row[1]' is NULL each time and reinforced by the FETCH_NUM result. Whereby, the array being returned only has the 0 index. So, duly index 1 would be an offset index.

Moreover, one thing I am quite confused by is the result of the FETCH_NUM and row0 debugging being different. For example, as illustrated above the values are 211 in the FETCH_NUM & 175 in the row0.

Debugging further, I also placed a call to log the backtrace on each iteration, when either of the rows index are not set.

Mage::log(Varien_Debug::backtrace(true, true), null, 'backtrace.log'); 

This has quickly shown:

2018-10-25T17:28:39+00:00 DEBUG (7): \<pre>#1 Magento_Db_Adapter_Pdo_Mysql[Zend_Db_Adapter_Abstract]#00000000450daa0800000000771f8a81#->fetchPairs(&Varien_Db_Select#00000000450dabb100000000771f8a81#, array()) called at [app/code/community/Activo/CatalogSearch/Model/Resource/Fulltext.php:97]
#2 Activo_CatalogSearch_Model_Resource_Fulltext#00000000450dabbb00000000771f8a81#->_prepareResult_193(&Mage_CatalogSearch_Model_Fulltext#00000000450dabad00000000771f8a81#, '', &Mage_CatalogSearch_Model_Query#00000000450daa6a00000000771f8a81#) called at [app/code/community/Activo/CatalogSearch/Model/Resource/Fulltext.php:29]
#3 Activo_CatalogSearch_Model_Resource_Fulltext#00000000450dabbb00000000771f8a81#->prepareResult(&Mage_CatalogSearch_Model_Fulltext#00000000450dabad00000000771f8a81#, '', &Mage_CatalogSearch_Model_Query#00000000450daa6a00000000771f8a81#) called at [app/code/core/Mage/CatalogSearch/Model/Fulltext.php:136]
#4 Mage_CatalogSearch_Model_Fulltext#00000000450dabad00000000771f8a81#->prepareResult() called at [app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php:147]
#5 Mage_CatalogSearch_Model_Resource_Fulltext_Collection#00000000450daad000000000771f8a81#->getFoundIds() called at [app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php:126]
#6 Mage_CatalogSearch_Model_Resource_Fulltext_Collection#00000000450daad000000000771f8a81#->_applySearchFilters() called at [app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php:113]
#7 Mage_CatalogSearch_Model_Resource_Fulltext_Collection#00000000450daad000000000771f8a81#->getSize() called at [app/code/core/Mage/CatalogSearch/Block/Layer.php:89]
#8 Mage_CatalogSearch_Block_Layer#00000000450daad500000000771f8a81#->canShowBlock() called at [app/design/frontend/rwd/default/template/catalog/layer/view.phtml:34]
#9 include('/var/www/html/ww...') called at [app/code/core/Mage/Core/Block/Template.php:241]
#10 Mage_CatalogSearch_Block_Layer[Mage_Core_Block_Template]#00000000450daad500000000771f8a81#->fetchView('frontend/rwd/def...') called at [app/code/core/Mage/Core/Block/Template.php:272]
#11 Mage_CatalogSearch_Block_Layer[Mage_Core_Block_Template]#00000000450daad500000000771f8a81#->renderView() called at [app/code/core/Mage/Core/Block/Template.php:286]
#12 Mage_CatalogSearch_Block_Layer[Mage_Core_Block_Template]#00000000450daad500000000771f8a81#->_toHtml() called at [app/code/core/Mage/Core/Block/Abstract.php:923]
#13 Mage_CatalogSearch_Block_Layer[Mage_Core_Block_Abstract]#00000000450daad500000000771f8a81#->toHtml() called at [app/code/core/Mage/Core/Block/Text/List.php:43]
#14 Mage_Core_Block_Text_List#00000000450daa8800000000771f8a81#->_toHtml() called at [app/code/core/Mage/Core/Block/Abstract.php:923]
#15 Mage_Core_Block_Text_List[Mage_Core_Block_Abstract]#00000000450daa8800000000771f8a81#->toHtml() called at [app/code/core/Mage/Core/Block/Abstract.php:641]
#16 Mage_Page_Block_Html[Mage_Core_Block_Abstract]#00000000450daa0100000000771f8a81#->_getChildHtml('left_first', true) called at [app/code/core/Mage/Core/Block/Abstract.php:585]
#17 Mage_Page_Block_Html[Mage_Core_Block_Abstract]#00000000450daa0100000000771f8a81#->getChildHtml('left_first') called at [app/design/frontend/rwd/default/template/page/3columns.phtml:55]
#18 include('/var/www/html/ww...') called at [app/code/core/Mage/Core/Block/Template.php:241]
#19 Mage_Page_Block_Html[Mage_Core_Block_Template]#00000000450daa0100000000771f8a81#->fetchView('frontend/rwd/def...') called at [app/code/core/Mage/Core/Block/Template.php:272]
#20 Mage_Page_Block_Html[Mage_Core_Block_Template]#00000000450daa0100000000771f8a81#->renderView() called at [app/code/core/Mage/Core/Block/Template.php:286]
#21 Mage_Page_Block_Html[Mage_Core_Block_Template]#00000000450daa0100000000771f8a81#->_toHtml() called at [app/code/core/Mage/Core/Block/Abstract.php:923]
#22 Mage_Page_Block_Html[Mage_Core_Block_Abstract]#00000000450daa0100000000771f8a81#->toHtml() called at [app/code/core/Mage/Core/Model/Layout.php:555]
#23 Mage_Core_Model_Layout#00000000450daa9700000000771f8a81#->getOutput() called at [app/code/core/Mage/Core/Controller/Varien/Action.php:390]
#24 Mage_CatalogSearch_ResultController[Mage_Core_Controller_Varien_Action]#00000000450daa9600000000771f8a81#->renderLayout() called at [app/code/core/Mage/CatalogSearch/controllers/ResultController.php:80]
#25 Mage_CatalogSearch_ResultController#00000000450daa9600000000771f8a81#->indexAction() called at [app/code/core/Mage/Core/Controller/Varien/Action.php:418]
#26 Mage_CatalogSearch_ResultController[Mage_Core_Controller_Varien_Action]#00000000450daa9600000000771f8a81#->dispatch('index') called at [app/code/core/Mage/Core/Controller/Varien/Router/Standard.php:254]
#27 Mage_Core_Controller_Varien_Router_Standard#00000000450daa2200000000771f8a81#->match(&Mage_Core_Controller_Request_Http#00000000450daa2800000000771f8a81#) called at [app/code/core/Mage/Core/Controller/Varien/Front.php:172]
#28 Mage_Core_Controller_Varien_Front#00000000450daa4400000000771f8a81#->dispatch() called at [app/code/core/Mage/Core/Model/App.php:365]
#29 Mage_Core_Model_App#00000000450daa1d00000000771f8a81#->run(array('scope_code' => '', 'scope_type' => 'store', 'options' => array())) called at [app/Mage.php:684]
#30 Mage::run('', 'store') called at [index.php:88]
\</pre>

Okay after spending a prolonged period of time debugging I am starting to believe it is a core bug, as magento in the prepareResult method:

public function prepareResult($object, $queryText, $query)
{
    $adapter = $this->_getWriteAdapter();
    $searchType = $object->getSearchType($query->getStoreId());

    $preparedTerms = Mage::getResourceHelper('catalogsearch')
        ->prepareTerms($queryText, $query->getMaxQueryWords());

    $bind = array();
    $like = array();
    $likeCond = '';
    if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
        || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
    ) {
        $helper = Mage::getResourceHelper('core');
        $words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
        foreach ($words as $word) {
            $like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
        }

        if ($like) {
            $likeCond = '(' . join(' OR ', $like) . ')';
        }
    }

    $mainTableAlias = 's';
    $fields = array('product_id');

    $select = $adapter->select()
        ->from(array($mainTableAlias => $this->getMainTable()), $fields)
        ->joinInner(array('e' => $this->getTable('catalog/product')),
            'e.entity_id = s.product_id',
            array())
        ->where($mainTableAlias . '.store_id = ?', (int)$query->getStoreId());

    $where = "";
    if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
        || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
    ) {
        $bind[':query'] = implode(' ', $preparedTerms[0]);
        $where = Mage::getResourceHelper('catalogsearch')
            ->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
    }
    if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
        $where .= ($where ? ' OR ' : '') . $likeCond;
    } elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
        $select->columns(array('relevance' => new Zend_Db_Expr(0)));
        $where = $likeCond;
    }

    if ($where != '') {
        $select->where($where);
    }

    $this->_foundData = $adapter->fetchPairs($select, $bind);

    return $this;
}

Found here:

/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php

Are selecting only one column but are using the Zend fetchPairs method. Whereby, it naturally assumes:

/** * Fetches all SQL result rows as an array of key-value pairs. * * The first column is the key, the second column is the * value. * * @param string|Zend_Db_Select $sql An SQL SELECT statement. * @param mixed $bind Data to bind into SELECT placeholders. * @return array */

So, no second column is being provided here.

  • This is the section you are talking about? public function fetchPairs($sql, $bind = array()) { $stmt = $this->query($sql, $bind); $data = array(); while ($row = $stmt->fetch(Zend_Db::FETCH_NUM)) { $data[$row[0]] = $row[1]; } return $data; } – Rebel May 8 '17 at 19:49
  • Aye line 814, but no idea why a core line is causing that ? – Vaishal Patel May 8 '17 at 19:51
  • one error be connected to the connected to the other. – Rebel May 8 '17 at 20:11
  • @VaishalPatel I have the same problem, did you find a solution? – EssGee Oct 23 '18 at 8:16
  • @EssGee Still not found a solution. But, looks to be caused by the second column missing. – Vaishal Patel Oct 25 '18 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.