The mysql user you're using don't have the perms to connect from that ip.
Does your script run on the server mysql runs on?
If you're gonna connect from a external server, you need to specify (in mysql db mysql, field users) either the ip to connect from, or a % to connect from anywhere.
knutm