This simple little function has been in use and working for quite some time but now seems to be broken after updating to PHP 7.X. Not sure why but it is giving an error of Undefined offset 0
on the row containing $row[0]
. I understand the error but not sure why it is there all of a sudden when it had been working. DBConnect()
is a custom function used throughout the site to fetch single or multiple rows, count rows, update, insert and delete data and is working everywhere else except here.
What do I do to repair it without, hopefully, modifying DBConnect()
?
function ListTableNames($DBname) {
$rowQuery = "SHOW TABLES FROM $DBname";
$rowTables = DBConnect($rowQuery,"Multiple", $DBname,"assoc");
$tableList = [];
foreach ($rowTables as $row) :
$tableList[] = $row[0];
endforeach;
return $tableList;
}
A portion of the DBConnect() function as used above:
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;
A var_dump($rowTables) shows:
array(29) {
[0]=>
array(1) {
["Tables_in_dbname"]=>
string(9) "table1"
}
[1]=>
array(1) {
["Tables_in_dbname"]=>
string(9) "table2"
}
[2]=>
array(1) {
["Tables_in_dbname"]=>
string(17) "table3"
}
[3]=>
array(1) {
["Tables_in_dbname"]=>
string(8) "table4"
}
}