Example #1
0
 /**
  * Match bindings
  * @param string $sql
  * @param array $binds
  * @param int $bindCount
  * @param int $ml
  * @return string
  */
 protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml)
 {
     // Make sure not to replace a chunk inside a string that happens to match the bind marker
     if ($c = preg_match_all("/'[^']*'/i", $sql, $matches)) {
         $c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', str_replace($matches[0], str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]), $sql, $c), $matches, PREG_OFFSET_CAPTURE);
         // Bind values' count must match the count of markers in the query
         if ($bindCount !== $c) {
             return $sql;
         }
     } else {
         if (($c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bindCount) {
             return $sql;
         }
     }
     do {
         $c--;
         $escapedValue = $this->db->escape($binds[$c]);
         if (is_array($escapedValue)) {
             $escapedValue = '(' . implode(',', $escapedValue) . ')';
         }
         $sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml);
     } while ($c !== 0);
     return $sql;
 }