+1  A: 

Kudos for your creative workarounds, but you should talk to your server administrator why the connection drops. This doesn't sound like normal behaviour.

Pekka
Ah, I thought it was normal (that I was using php for something it wasn't intended)
skerit
+1  A: 

If this is a script that is purely internal, I don't see any major issues (generally allowing untrusted users to see the error messages is a bad idea).

Sounds like the MySQL issue is a server problem. Depending on server traffic you may be running into a limit on the number of connections that the database can accept.

acrosman