<?php
function FormatSql($query, array $params = []) {
$patt = '~ ([\'"`]) # capture this quote character
(?:\\\\.|(?!\1).)* # any escaped character, or
# any character that isn\'t the captured one
\1 # the captured quote again
(*SKIP)(*FAIL) # ignore this
|
\?\?? # one or two question marks
|
::?\w+ # word characters marked with one or two colons~x';
return preg_replace_callback($patt, function ($matches) use (&$params) {
if(!isset($matches[1])) return $matches[0];
switch($matches[1]) {
case '?':
if(!$params) throw new \DomainException("Not enough params");
return '*snip*';
case '??':
if(!$params) throw new \DomainException("Not enough params");
return '*snip*';
case ':':
if(!array_key_exists($matches[2], $params)) throw new \DomainException("\"$matches[2]\" param not provided");
return '*snip*';
case '::':
if(!array_key_exists($matches[2], $params)) throw new \DomainException("\"$matches[2]\" param not provided");
return '*snip*';
}
throw new \Exception("Bad regex");
}, $query);
}
$bigStr = str_repeat('x', 443000);
$bigQuery = "INSERT INTO `emr_doc_file` (`emr_doc_id`, `edf_file`, `edf_mimetype`, `edf_upload_date`) VALUES ('108', x'$bigStr', 'application/pdf', 1490978009)";
$result = FormatSql($bigQuery, []);
if($result === null) {
throw new \Exception("preg error: " . preg_last_error() . "\nsee: http://php.net/manual/en/pcre.constants.php#117743");
}
echo substr($result,0,100).PHP_EOL;
Fatal error: Uncaught Exception: preg error: 6
see: http://php.net/manual/en/pcre.constants.php#117743 in /in/GdtmP:38
Stack trace:
#0 {main}
thrown in /in/GdtmP on line 38
Process exited with code 255.