0

PHP code designed to catch an error caused by a query that takes too long to execute (in this case one second, by design).

$conn = mysqli_connect("localhost", "user", "pass", "db");

$conn->query('SET SESSION MAX_EXECUTION_TIME = 1000'); 

try{
$results = mysqli_query($conn, $sql);
$num = mysqli_fetch_assoc($results)['COUNT(1)'];
}

catch(Exception $e) {
  echo "query probably took too long: ". $e;
}

The following warnings are displayed on the browser:

Warning: mysqli_query(): (HY000/3024): Query execution was interrupted, maximum statement execution time exceeded 

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool

Why am I still getting hit with these warnings on the browser? Surely, if I am catching these errors then I don't need warnings. I understand that warnings can be supressed, but is it possible to amend the code to prevent the warnings?

Edit: $sql is must the query, "SELECT Count(1) FROM table WHERE..."

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Ned Hulton
  • 477
  • 3
  • 12
  • 27

0 Answers0