Skip to content

Commit 1efff31

Browse files
authored
Merge pull request barryvdh#508 from melkorr/bugfix-db-with-params
Bugfix for when sql param is not a questionmark
2 parents ca22869 + 336bd06 commit 1efff31

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/DataCollector/QueryCollector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ public function addQuery($query, $bindings, $time, $connection)
9999

100100
$bindings = $this->checkBindings($bindings);
101101
if (!empty($bindings) && $this->renderSqlWithParams) {
102-
foreach ($bindings as $binding) {
103-
$query = preg_replace('/\?/', $pdo->quote($binding), $query, 1);
102+
foreach ($bindings as $key => $binding) {
103+
$regex = is_numeric($key) ? '/\?/' : "/:{$key}/";
104+
$query = preg_replace($regex, $pdo->quote($binding), $query, 1);
104105
}
105106
}
106107

@@ -196,7 +197,7 @@ protected function performQueryAnalysis($query)
196197
}
197198
return implode("<br />", $hints);
198199
}
199-
200+
200201
/**
201202
* Use a backtrace to search for the origin of the query.
202203
*/
@@ -291,7 +292,7 @@ protected function normalizeFilename($path)
291292
}
292293
return str_replace(base_path(), '', $path);
293294
}
294-
295+
295296
/**
296297
* Reset the queries.
297298
*/

0 commit comments

Comments
 (0)