0

How can I connect to MySQL database online from localhost using php?

I have read through all I could laid my hands on but to no avail. I read through Connect to an online MySQL database from localhost, Connect to server database from localhost, Connect to server database from localhost and some as well but none of them helped.

I tried

$dbhost = 'infonetemonitor.com'; //$db['host'];
$dbuser = '****';//$db['user'];
$dbpass = '****';//$db['pass'];
$dbname = 'info1_quiz';//$db['dbname'];

//Mysqli
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
    printf("MySQLi connection failed: ", mysqli_connect_error());
    exit();
}

But this error was generated:

Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'info1_senetorial'@'41.58.56.26' (using password: YES) in C:\wamp64\www\COSTMI\includes\liveconnect.php on line 10

I thought it could be due to the fact that I didn't add an ip to Remote MySQL so I did but still nothing change.

In the database, I tried to grant privileges

GRANT ALL PRIVILEGES ON info1_quiz.* TO 'info1_senetorial'@'41.58.56.26' WITH GRANT OPTION;

but this error was displayed:

MySQL said:

1044 - Access denied for user 'infon10'@'localhost' to database 'mysql'

How can I go about it?

  • 2
    Possible duplicate of [Warning: mysqli\_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)](https://stackoverflow.com/questions/25174183/warning-mysqli-connect-hy000-1045-access-denied-for-user-usernameloca) – Obsidian Age Mar 13 '19 at 02:02
  • can you add the contents of mysql.user to the question? (only user name and host needed) MySQL is picky about the ordering of entries in that table – Joni Mar 13 '19 at 03:02

1 Answers1

0

Try to replace the host name with the Host IP address and check again. this should allow you to connect to the DB. If you want to connect with the domain name then you should configure MySQL to understand with the domain name associated in the apache.conf file.

  • I tried it but still getting **Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'infon10_senetorial'@'41.58.104.52' (using password: YES) in** – Olajumoke Ademilade Mar 13 '19 at 02:37