Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jreinke/2af96be267854a1bb1aa3df8ae95fdc8 to your computer and use it in GitHub Desktop.
Save jreinke/2af96be267854a1bb1aa3df8ae95fdc8 to your computer and use it in GitHub Desktop.
Display Magento 2 SQL queries
<?php
/*
Edit file vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php
and add the following code at line 237
*/
$sqlQuery = $sql;
if (is_string(key($bind))) {
foreach ($bind as $field => $value) {
$sqlQuery = str_replace($field, $this->quote($value), $sqlQuery);
}
} else if (is_numeric(key($bind))) {
$offset = 0;
foreach ($bind as $value) {
$pos = strpos($sqlQuery, '?', $offset);
if (null === $value) {
$value = 'NULL';
} else if (is_string($value)) {
$value = $this->quote($value);
}
$sqlQuery = substr_replace($sqlQuery, $value, $pos, 1);
$offset = $pos + strlen($value);
}
}
echo '<pre>';print_r($sqlQuery);echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment