Mysqli error handling

Currently, the code uses different indicators to determine failed queries. For example, an UPDATE query with no affected rows will count as an error, which doesn't make a lot of sense.

It's better to check for real SQL errors. This is done by telling MySQLi to throw exceptions in case of an error. Those exceptions can then be caught and replaced with custom error messages.