<?php
/**
*
*/
function iQuery($sql) {
$dbcon = mysqli_connect("localhost", "root", "159753", "radius");
if ($dbcon->connect_error) {
return false;
}
if (!is_array($sql)) {
$res = $dbcon->query($sql);
if ($res) {
$arr = [];
while ($item = $res->fetch_array()) {
array_push($arr, $item);
}
$ttr = null;
if (preg_match("/SQL_CALC_FOUND_ROWS/i", $sql)) {
$qttr = $dbcon->query("select found_rows()");
if ($qttr) {
while ($atom = $qttr->fetch_array()) {
$ttr = $atom[0];
}
}
}
return ["insert_id" => $dbcon->insert_id, "affected_rows" => $dbcon->affected_rows, "result" => $arr, "total_rows" => $ttr];
} else {
return false;
}
} else {
$rtn_arr = [];
foreach ($sql as $s) {
$res = $dbcon->query($s);
if ($res) {
$arr = [];
while ($item = $res->fetch_array()) {
array_push($arr, $item);
}
$ttr = null;
if (preg_match("/SQL_CALC_FOUND_ROWS/i", $sql)) {
$qttr = $dbcon->query("select found_rows()");
if ($qttr) {
while ($atom = $qttr->fetch_array()) {
$ttr = $atom[0];
}
}
}
array_push($rtn_arr, ["insert_id" => $dbcon->insert_id, "affected_rows" => $dbcon->affected_rows, "result" => $arr, "total_rows" => $ttr]);
} else {
return false;
}
}
return $rtn_arr;
}
}
?>