Cross Vander
Cross Vander

Reputation: 2177

PHP Localhost Application connect to server database

I want to ask about how to connect my localhost application (C:xampp/htdocs/myproject) to database at my server host (www.someweb.somedomain)?

Am I possible to do that? If it is, how to connect it at my php config? Right now my config (server.php) is:

<?php
    $host = "my web IP public:3306";
    $user = "root";
    $pass = "";
    $db = "dispatcherDB";

    $conn = mysql_connect($host, $user, $pass) or die ("Cant connect to mySQL");
    mysql_select_db($db);
?>

what I got:

Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\XMS\server.php on line 7

So, what must I filled for $host? I'm trying using website IP, it still can't connect. Maybe there's someone here have experience at this problem?

Sorry for my bad English

Upvotes: 2

Views: 8629

Answers (2)

000
000

Reputation: 3950

If you have cPanel access to the remote server then you need to mention that from which ip addresses it should allow access to MySQL..

In cPanel you will get Remote MySQL under heading Databases: enter image description here

Clicking Remote MySQL will give you the option to add hosts from where you want to allow connections to your MySQL server:

enter image description here

Also, you can check localhost without specifying port number as value of $host..

Upvotes: 3

someone
someone

Reputation: 6572

Probably Mysql server is not allowed root access from remote servers.

you could check this post

Upvotes: 0

Related Questions