It looks like you're trying to connect to your database from a different server. Is your PHP script still running on your own PC?
The message you get is because you try to reach the database from the computer at address 31.170.163.50, which is not allowed. Quite often, when you have 'normal' simple, shared hosting, you are not allowed to use the database from other computers directly. Only the scripts on the server itself are allowed to use the database.
So, the solution would be: Put everything, scripts and database, on your web hosting platform, and use localhost or 127.0.0.1 when your PHP script needs to connect to your database.