PCHomepage
Programmer
I created what I thought was a basic and simple function to help in quick database functionality. The connection is working as I can select single or multiple records but I've apparently missed something in executing a function for updating or inserting. There are no errors but $mysqli->query($Query); seems to do nothing. What have I forgotten? Here is the whole function with the area in question in red:
If I echo the query to the screen, which confirms that it is passing into the proper portion of the conditional, and run it manually in HeidiSQL it works but not in the function. Any help is appreciated.
PHP:
function DBConnect($Query, $ActionType) {
if (!$Query) {
exit();
}
include "config.php";
$mysqli = new mysqli($dbhost, $dbusername, $dbpass, $dbname);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($ActionType == "Select") {
$result = $mysqli->query($Query);
$row = $result->fetch_assoc();
return $row;
[COLOR=red]} elseif ($ActionType == "Update" || $ActionType == "Insert" || $ActionType == "Delete") {
$mysqli->query($Query);[/color]
} elseif ($ActionType == "Multiple") {
if ($result = $mysqli->query($Query)) {
$numrowsCat = $result->num_rows;;
if ($numrowsCat > 1) {
$result = $mysqli->query($Query);
while($row = $result->fetch_array()) {
$results_array[] = $row;
}
return $results_array;
}
}
} elseif ($ActionType == "Count") {
if ($result = $mysqli->query($Query)) {
return $result->num_rows;
}
}
$_SESSION['ActionSubmitted'] = $ActionType;
if ($ActionType && isset($result)) {
$_SESSION['ActionType'] = "$ActionType Successful";
$result->close();
}
$mysqli->close();
}
If I echo the query to the screen, which confirms that it is passing into the proper portion of the conditional, and run it manually in HeidiSQL it works but not in the function. Any help is appreciated.