I am trying to handle errors for faulty queries sent by mysqli_query to my database, but for some reason mysqli_query() does not return anything when a faulty query is passed through it. The function works fine when the query is valid, and returns what it is supposed to, but when a faulty query is executed the function returns nothing, and at this point I am not even sure it is returning anything because it does not execute any of the following lines when this occurs. Here is the code I am trying to run:
<?php
//Functions
function findTable($con, $tableName) {
$query = "SELECT * FROM $tableName";
if (!mysqli_query($con, $query)) {
echo("Errorcode: " . mysqli_errno($con));
exit();
}
echo "Table exists";
}
//Connect to DB
$con = mysqli_connect("localhost", "root", "pass", "db");
//Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
echo "Connected to DB;\r\n";
findTable($con, "");
mysqli_close($con);
?>
Output for this currently looks like this:
Connected to DB;
Anyone know what could be causing this issue? mysqli seems to be working fine on my system otherwise.