To add error handling for all the database statements (connection, query, prepare, execute), without having to add program logic at each statement, just use exceptions for errors and let php catch the exception, where it will use its error_reporting, display_errors, and log_errors settings to control what happens with the actual error information. To use exceptions for the php mysqli extension, add the following line of code before you make the database connection -
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
By just changing the php error settings, you can display the database errors when learning, developing, and debugging code/queries, or log the database errors when on a live/public server.