I have a live database-driven web application that is almost entirely built on php/mysql interaction. It's been live for two and a half years and in that time the code has not changed and I've never had an issue.
About a week ago, the site just suddenly stopped pulling any data from the database. At first I thought the host was just down, it happens sometimes. But the problem persisted and my users started noticing and asking questions, so I had to investigate.
I first tried connecting directly to the database via MySQL Workbench. This was successful. This told me a few things: that the database was intact and unharmed; that there was no problem with the url/username/password/etc; and that the problem therefore must be a php issue.
Upon debugging the php, I became perplexed because the php wasn't behaving as though it couldn't connect; rather, it was behaving as if it was connecting to an empty database. It didn't throw any error message upon connecting, but then would return nothing from queries that 100% should've returned something.
Long story short, after banging my head against a wall for a while, I got to a point where I narrowed the problem down to this standard construct used to loop through a returned MySQL object:
while($row = $result->fetch_array(MYSQL_ASSOC))
do stuff
This has always worked. I've never, ever had a problem with it. But I'm having a problem now, so, on a whim I tried changing it to
while($row = $result->fetch_assoc())
do stuff
And just like that, it started working again. Then I tried
while($row = $result->fetch_array())
do stuff
This also worked. Then I tried
while($row = $result->fetch_array(MYSQLI_ASSOC))
do stuff
and that too worked.
So the problem is that for some reason, the MySQL_ASSOC parameter stopped working all of a sudden. My question is, what would cause that to happen?
My only guess is the version of PHP my hosting account is using changed on its own for some reason. I checked and it's currently using "PHP 7.2. FastCGI". Unfortunately, I don't remember what version it was using before. I can change the version if I want, all the way back to 5.6. I just don't know if I should.
Does anyone have any idea what could've caused this to happen?