I get this error sometimes, when there are too many people using the sql database at a time.
I'm quite new to sql, but there's a close connection like, mysql_close($connection) that may help. its optional in the code but I do think its good practice to close a connection when the query is done. I don't know if that'll help your problem or it'll make any difference.