/** * 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('Invalid connection')); } return $connection->query($query); } throw new LocalizedException(new Phrase('Invalid query')); }