Switch the order of these two statements. This way, if `check_table_cols` fail, we won't connect to the database, while we are now connecting even if it fails.