ajax + php yet another suggestion for correct error handling

Solution:

From theĀ jQuery ajax documentation:

error(jqXHR, textStatus, errorThrown)
A function to be calledĀ if the request fails. …

On server-side the request has already succeed. Normally the resulting callback will be the success handler, not the error handler.

You should handle the mysql_connect error in the ajax-success handler.