php iquery
<?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;
}
}
?>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。