cancel
Showing results for 
Search instead for 
Did you mean: 
New

Cant connect mysql database through php script remotely

I purchased a Linux Web Hosting because I need an online MySQL database. i have linux hosting.I need to access that database using .php scripts when i tried my code in localhost i got the result but if i put my website ip address to connect a data base i have created through cpanel with php admin . The php script will not give error but also will give no result. just blank. i will confess that i am novince in this area ...connecting a remote data base. please can someone be patient to tell me steps i should take to get my database running.  This is my code

<?php
//Sample Database Connection Syntax for PHP and MySQL.

//Connect To Database

$hostname="160.153.91.99";
$username="odumosu";
$password="sobanu5555";
$dbname="godamfilm";
$usertable="staff";
$yourfield = "name";
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);

# Check If Record Exists

$query = "SELECT * FROM $usertable";

$result = mysql_query($query);

if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Name: ".$name."
";
}
}
?> 

when i run this on localhost without ip address it comes with result but if i have it access the mysql that i created in godaddy cpanel it comes out without resuly.