Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #24 from aa6my/master
Browse files Browse the repository at this point in the history
Fixing the issue interpolateQuery
  • Loading branch information
lonnieezell authored Aug 3, 2016
2 parents 78199e0 + b130844 commit 2a680ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
$config['eloquent'] = FALSE;
$config['uri_string'] = TRUE;
$config['view_data'] = TRUE;
$config['query_toggle_count'] = 50;
$config['query_toggle_count'] = 50;
29 changes: 28 additions & 1 deletion libraries/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ protected function _compile_eloquent()
$time = number_format($q['time']/1000, 4);
$total += $q['time']/1000;

$query = interpolateQuery($q['query'], $q['bindings']);
$query = $this->interpolateQuery($q['query'], $q['bindings']);
foreach ($highlight as $bold)
$query = str_ireplace($bold, '<b>'.$bold.'</b>', $query);

Expand All @@ -274,6 +274,33 @@ protected function _compile_eloquent()
return $output;
}

public function interpolateQuery($query, array $params) {
$keys = array();
$values = $params;

//build a regular expression for each parameter
foreach ($params as $key => $value) {
if (is_string($key)) {
$keys[] = "/:" . $key . "/";
} else {
$keys[] = '/[?]/';
}

if (is_string($value))
$values[$key] = "'" . $value . "'";

if (is_array($value))
$values[$key] = implode(',', $value);

if (is_null($value))
$values[$key] = 'NULL';
}

$query = preg_replace($keys, $values, $query, 1, $count);

return $query;
}


// --------------------------------------------------------------------

Expand Down

0 comments on commit 2a680ed

Please sign in to comment.