private function explainQuery($query, $bindings = null, &$dbh)
{
// Check if query is a SELECT
if (substr($query, 0, 6) != 'SELECT') {
return '';
}
if (is_null($bindings)) {
$explain_sth = $dbh->query('EXPLAIN ' . $query);
} else {
$explain_sth = $dbh->prepare('EXPLAIN ' . $query);
if ($explain_sth != false) {
$result = $explain_sth->execute($bindings);
if (!$result) {
return '';
}
}
}
if ($explain_sth === false) {
$this->logErrorInfo($dbh, 'debug');
return 'statement error';
} else {
$explanation = $explain_sth->fetchAll(\PDO::FETCH_ASSOC);
return $explanation;
}
}