Skip to content

Commit

Permalink
always use fetch_field to grab duplicate fields in resultset
Browse files Browse the repository at this point in the history
  • Loading branch information
michabbb committed Dec 14, 2018
1 parent 8dded53 commit 07daa89
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions MySQLiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,53 +179,43 @@ public function query($sql, array $params = []) {
$ResponseObj->numrows = 0;
$ResponseObj->affected_rows = ($stmt->affected_rows > 0) ? $stmt->affected_rows : 0;

if ($paramsWithTypes) {
$meta = $stmt->result_metadata();

$meta = $stmt->result_metadata();
$fields = [];
$fields = [];

if ($meta) {
if ($meta) {

$dupcounter = [];
$dupcounter = [];

while ($field = $meta->fetch_field()) {
$var = $field->name;
$$var = null;
if (array_key_exists($field->name,$dupcounter)) {
$var = $var.$dupcounter[$field->name];
}
$fields[$var] = &$$var;
if (!array_key_exists($field->name,$dupcounter)) {
$dupcounter[$field->name]=0;
}
$dupcounter[$field->name]++;
while ($field = $meta->fetch_field()) {
$var = $field->name;
$$var = null;
if (array_key_exists($field->name,$dupcounter)) {
$var = $var.$dupcounter[$field->name];
}

if (count($paramsWithTypes)) {
\call_user_func_array([$stmt, 'bind_result'], $fields);
$fields[$var] = &$$var;
if (!array_key_exists($field->name,$dupcounter)) {
$dupcounter[$field->name]=0;
}
$dupcounter[$field->name]++;
}

$i = 0;
while ($stmt->fetch()) {
$ResponseObj->numrows++;
$ResponseObj->result[$i] = [];
foreach ($fields as $k => $v) {
if ($this->lowerTableFields) {
$k = strtolower($k);
}
$ResponseObj->result[$i][$k] = $v;
\call_user_func_array([$stmt, 'bind_result'], $fields);

$i = 0;
while ($stmt->fetch()) {
$ResponseObj->numrows++;
$ResponseObj->result[$i] = [];
foreach ($fields as $k => $v) {
if ($this->lowerTableFields) {
$k = strtolower($k);
}
$i++;
$ResponseObj->result[$i][$k] = $v;
}
$i++;
}
} else {
$result = $stmt->get_result();
if ($result!==false) {
while ($row = $result->fetch_assoc()) {
$ResponseObj->numrows++;
$ResponseObj->result[] = $this->lowerTableFields ? array_change_key_case($row, CASE_LOWER) : $row;
}
}
$ResponseObj->error = 'result_metadata returned false';
}

$stmt->free_result();
Expand Down

0 comments on commit 07daa89

Please sign in to comment.