Is the MySQL daemon up and running? Can you connect to the server using the command line client? If not, start the server and re-run your application again.
I would advise you to separate your database code from user interface stuff. You'll regret combining the two the way you have someday.