And you are sure this is the part of the code giving the error? I ask because nothing should have changed with this. PHP 8.1 didn’t change any behavior for that related function or it would have been documented in the mysqli_fetch_array documentation page. It would have given you the same error even back in PHP 7. Make sure that your $getContent is not being set to NULL. This would happen if your query doesn’t have anymore rows.
Could your query be different than it was before? Did maybe the row you originally select get deleted?
The error is happening all over the place on many pages on many websites.
In the error log the line that always has the error is the one with the “$getContent = mysqli_fetch_array($getContent);” code on it.
By the looks of it is is only happening if there is nothing in the database to return.
EXAMPLE: I have a system that does my books and looks for a tax code… if there is nothing in the DB for the tax code the result is NULL and then the error appears.
From my research I think I need to add something like if it is empty don’t do anything?
I have also had issues with my $_GET[‘somthething’]; code and have had to updates them all to something like - if (isset($_GET[‘somthething’]) == true) { $_GET[‘somthething’] = $_GET[‘somthething’]; } else { $_GET[‘somthething’] = “”; } which has fixed that error.
I’m still learning PHP, but I think that’s always been the case - if you try to use an array member that doesn’t exist, PHP has “always” to my knowledge complained about it.
Are you sure the log settings aren’t different?
That doesn’t make sense to me, because you’re not trying to access an array offset in that line of code - you’re trying to create an array by retrieving the next row from the results object. It’s the print row that actually tries to access an array element.
Aren’t you going to run into a problem anyway with this bit of code if it has more than one row returned because you’re overwriting the results object with the first row? Or does the example only ever return one row?
$getContent = mysqli_query($con,‘SELECT whatever FROM table WHERE this=“this” AND that=“that”’);
$getContent = mysqli_fetch_array($getContent);
What would probably be better is checking if what you get back is NULL…
$getContent = mysqli_query($con,‘SELECT something FROM whatever WHERE this=“this”’);
if (is_null($getContent)) {
// Throw some kind of exception
}
// Here would then be ok to use $getContent