Permalink
Browse files

MDL-40266 improve emulate_bound_params() for mysqli

Looping over large numbers of items with array_shift() is expensive.
Reverse the array and fetch items from the top of the pile.
  • Loading branch information...
1 parent 490bf4e commit e13acecad76875d5b442a24730ef7d038c37621b @martin-langhoff martin-langhoff committed with danpoltawski Jun 12, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/dml/mysqli_native_moodle_database.php
@@ -814,8 +814,8 @@ protected function emulate_bound_params($sql, array $params=null) {
return $sql;
}
// ok, we have verified sql statement with ? and correct number of params
- $parts = explode('?', $sql);
- $return = array_shift($parts);
+ $parts = array_reverse(explode('?', $sql));
+ $return = array_pop($parts);
foreach ($params as $param) {
if (is_bool($param)) {
$return .= (int)$param;
@@ -829,7 +829,7 @@ protected function emulate_bound_params($sql, array $params=null) {
$param = $this->mysqli->real_escape_string($param);
$return .= "'$param'";
}
- $return .= array_shift($parts);
+ $return .= array_pop($parts);
}
return $return;
}

0 comments on commit e13acec

Please sign in to comment.