Sometimes a webhosting provider will require you to specify the MySQL server name and port number.
For example if the MySQL server name is db.php-mysql-bodhost.com and the port number is 3306 then you you can modify the above code to :
HTML Code:
<?php
$dbhost = 'db.php-mysql-bodhost.com:3306';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'petstore';
mysql_select_db($dbname);
?>