I have a function that can make different types of database connections and, simplified below with only two such $ActionType values, it is the second one I am having difficulty with. No errors but no results either. Any ideas?
The query contains multiple queries such as:
$Query = "SQL statement #1;";
$Query .= "SQL statement #2;";
$Query .= "SQL statement #3;";
and this is the function, cut down to fit here:
function DBConnect($Query, $ActionType, $DBname, $selType='array') {
$ActionType = trim(strtolower($ActionType));
if (!$Query) :
exit();
endif;
$MySQLError = "";
$mysqli = dbConn($DBname);
if ($Query && $mysqli->connect_errno != 0):
$MySQLError = "<div class=\"ErrorMessage\">";
$MySQLError .= printf("Connect failed: %s\n", $mysqli->connect_error);
$MySQLError .= "</div>\n\n";
return $MySQLError;
exit();
endif;
switch ($ActionType) :
case "multiple":
if ($result = $mysqli->query($Query)) :
$numrowsCat = $result->num_rows;
if ($numrowsCat >= 1) :
$result = $mysqli->query($Query);
if ($selType === "assoc") :
while($row = $result->fetch_assoc()) :
$results_array[] = $row;
endwhile;
else :
while($row = $result->fetch_array()) :
$results_array[] = $row;
endwhile;
endif;
return $results_array;
endif;
$MySQLError = ($mysqli->connect_errno) ? mysqli_error($mysqli) : "";
$mysqli->close();
if ($MySQLError) return $MySQLError;
endif;
break;
case "multiquery":
if ($result = $mysqli->multi_query($Query)) :
if ($result) :
while($row = $result->fetch_array()) :
$results_array[] = $row;
endwhile;
return $results_array;
endif;
$MySQLError = ($mysqli->connect_errno) ? mysqli_error($mysqli) : "";
$mysqli->close();
if ($MySQLError) return $MySQLError;
endif;
break;
endswitch;
}