Skip to content

Commit 2fe2f5e

Browse files
committed
Simplified and fixed broken multi name parameter code
1 parent 915bf8b commit 2fe2f5e

2 files changed

Lines changed: 15 additions & 27 deletions

File tree

src/Mysqli/MysqliStatement.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function prepareParameterKeyMapping($sql)
158158
$quoteChar = '';
159159
$literal = '';
160160
$mapping = [];
161-
$replace = [];
161+
$position = 0;
162162
$matches = [];
163163
$pattern = '/([:][a-zA-Z0-9_]+)/';
164164

@@ -198,15 +198,14 @@ public function prepareParameterKeyMapping($sql)
198198
}
199199

200200
if (isset($mapping[$match[0]])) {
201-
$mapping[$match[0]] = is_array($mapping[$match[0]]) ? $mapping[$match[0]] : [$mapping[$match[0]]];
202-
$mapping[$match[0]][] = \count($mapping);
203-
} else {
204-
$mapping[$match[0]] = \count($mapping);
201+
$mapping[$match[0]][] = [];
205202
}
206-
$endOfPlaceholder = $match[1] + strlen($match[0]);
203+
204+
$mapping[$match[0]][] = $position++;
205+
$endOfPlaceholder = $match[1] + strlen($match[0]);
207206
$beginOfNextPlaceholder = $matches[0][$i + 1][1] ?? strlen($substring);
208207
$beginOfNextPlaceholder -= $endOfPlaceholder;
209-
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
208+
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
210209
}
211210
} else {
212211
$literal .= $substring;
@@ -378,14 +377,9 @@ public function execute(?array $parameters = null)
378377
foreach ($this->bindedValues as $key => &$value) {
379378
$paramKey = $this->parameterKeyMapping[$key];
380379

381-
if (is_scalar($this->parameterKeyMapping[$key])) {
382-
$params[$paramKey] =& $value;
383-
$types[$paramKey] = $this->typesKeyMapping[$key];
384-
} else {
385-
foreach ($paramKey as $currentKey) {
386-
$params[$currentKey] =& $value;
387-
$types[$currentKey] = $this->typesKeyMapping[$key];
388-
}
380+
foreach ($paramKey as $currentKey) {
381+
$params[$currentKey] =& $value;
382+
$types[$currentKey] = $this->typesKeyMapping[$key];
389383
}
390384
}
391385
} else {

src/Sqlsrv/SqlsrvStatement.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function prepareParameterKeyMapping($sql)
163163
$quoteChar = '';
164164
$literal = '';
165165
$mapping = [];
166-
$replace = [];
166+
$position = 0;
167167
$matches = [];
168168
$pattern = '/([:][a-zA-Z0-9_]+)/';
169169

@@ -203,16 +203,14 @@ public function prepareParameterKeyMapping($sql)
203203
}
204204

205205
if (isset($mapping[$match[0]])) {
206-
$mapping[$match[0]] = is_array($mapping[$match[0]]) ? $mapping[$match[0]] : [$mapping[$match[0]]];
207-
$mapping[$match[0]][] = \count($mapping);
208-
} else {
209-
$mapping[$match[0]] = \count($mapping);
206+
$mapping[$match[0]][] = [];
210207
}
211208

209+
$mapping[$match[0]][] = $position++;
212210
$endOfPlaceholder = $match[1] + strlen($match[0]);
213211
$beginOfNextPlaceholder = $matches[0][$i + 1][1] ?? strlen($substring);
214212
$beginOfNextPlaceholder -= $endOfPlaceholder;
215-
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
213+
$literal .= '?' . substr($substring, $endOfPlaceholder, $beginOfNextPlaceholder);
216214
}
217215
} else {
218216
$literal .= $substring;
@@ -492,12 +490,8 @@ private function prepare()
492490
if (isset($this->parameterKeyMapping[$key])) {
493491
$paramKey = $this->parameterKeyMapping[$key];
494492

495-
if (is_scalar($this->parameterKeyMapping[$key])) {
496-
$params[$paramKey] = $variable;
497-
} else {
498-
foreach ($paramKey as $currentKey) {
499-
$params[$currentKey] = $variable;
500-
}
493+
foreach ($paramKey as $currentKey) {
494+
$params[$currentKey] = $variable;
501495
}
502496
} else {
503497
$params[] = $variable;

0 commit comments

Comments
 (0)