The issue lies in how MySQL handles the error when a query fails. When the inner query fails with the 1932 error (“Table doesn’t exist”), MySQL invalidates the database connection. After that, any subsequent query attempts using the same connection will also fail. This is why you encounter errors with the next query $srow = mysqli_fetch_array($sres).
Root Cause:
The invalidation of the connection happens because 1932 is a critical error. Although you tried to handle it with a try-catch, the MySQL connection is already unusable after such an error.
Solutions:
Solution 1: Validate Table Existence Before Querying
Before executing the inner query, check if the table exists using a safe query like this:
php
Copy code
$vquery = 'SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "' . $srow["TABLE_SCHEMA"] . '" AND TABLE_NAME = "' . $prefix . 'configuration"';
$vres = mysqli_query($conn, $vquery);
if (mysqli_fetch_array($vres)[0] > 0) {
$vquery = 'SELECT value FROM `' . $srow["TABLE_SCHEMA"] . '`.' . $prefix . 'configuration WHERE name="PS_VERSION_DB"';
try {
$vres = @mysqli_query($conn, $vquery);
} catch (Throwable $t) {
continue;
}
$vrow = mysqli_fetch_array($vres);
// ... further processing
}
This approach ensures you query only valid tables.