Granada\ORM::_log_query PHP Method

_log_query() protected static method

This works by manually binding the parameters to the query - the query isn't executed like this (PDO normally passes the query and parameters to the database which takes care of the binding) but doing it this way makes the logged queries more readable.
protected static _log_query ( string $query, array $parameters, string $connection_name ) : boolean
$query string
$parameters array An array of parameters to be bound in to the query
$connection_name string Which connection to use
return boolean
    protected static function _log_query($query, $parameters, $connection_name)
    {
        // If logging is not enabled, do nothing
        if (!self::$_config[$connection_name]['logging']) {
            return false;
        }
        if (!isset(self::$_query_log[$connection_name])) {
            self::$_query_log[$connection_name] = array();
        }
        if (count($parameters) > 0) {
            // Escape the parameters
            $parameters = array_map(array(self::$_db[$connection_name], 'quote'), $parameters);
            // Avoid %format collision for vsprintf
            $query = str_replace("%", "%%", $query);
            // Replace placeholders in the query for vsprintf
            if (false !== strpos($query, "'") || false !== strpos($query, '"')) {
                $query = Orm\String::str_replace_outside_quotes("?", "%s", $query);
            } else {
                $query = str_replace("?", "%s", $query);
            }
            // Replace the question marks in the query with the parameters
            $bound_query = vsprintf($query, $parameters);
        } else {
            $bound_query = $query;
        }
        self::$_last_query = $bound_query;
        self::$_query_log[$connection_name][] = $bound_query;
        if (is_callable(self::$_config[$connection_name]['logger'])) {
            $logger = self::$_config[$connection_name]['logger'];
            $logger($bound_query);
        }
        return true;
    }
ORM