_getStatement($query, $connection); $args['idx'] = 0; while ($row = $stmt->fetch()) { $args['row'] = $row; foreach ($callbacks as $callback) { $result = call_user_func($callback, $args); if (!empty($result)) { $args = array_merge($args, (array)$result); } } $args['idx']++; } return $this; } /** * Fetch Zend statement instance * * @param \Zend_Db_Statement_Interface|\Magento\Framework\DB\Select|string $query * @param AdapterInterface $connection * @return \Zend_Db_Statement_Interface * @throws LocalizedException */ protected function _getStatement($query, AdapterInterface $connection = null) { if ($query instanceof \Zend_Db_Statement_Interface) { return $query; } if ($query instanceof \Zend_Db_Select) { return $query->query(); } if (is_string($query)) { if (!$connection instanceof AdapterInterface) { throw new LocalizedException( new Phrase('The connection is invalid. Verify the connection and try again.') ); } return $connection->query($query); } throw new LocalizedException(new Phrase('The query is invalid. Verify the query and try again.')); } }