2

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

Cross Vander
  • 2,077
  • 2
  • 19
  • 33
  • 1
    The only way you will be able to do this is if your server `www.someweb.somedomain` explicitly allows external connections to access port 3306. I would think it would not want to, but perhaps you can whitelist the IP you expect to connect from? Honestly, I don't know how to do this, but I could look it up.... <_ – Explosion Pills Nov 14 '12 at 04:54
  • at my cpanel, there's a menu called "remote mysql" I click that and add my IP. it's just same. Refused. I'm trying to change myweb.mydomain:3307 still refused. – Cross Vander Nov 14 '12 at 04:56
  • you need to create a user and additionally grant him privileges.. – 000 Nov 14 '12 at 04:59

2 Answers2

3

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..

000
  • 3,976
  • 4
  • 25
  • 39
  • This question deserves more elaboration of the answer (in my opinion). Could you do that? I'm quite confused about solving this problem. – falcon Jul 14 '14 at 07:38
0

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

you could check this post

Community
  • 1
  • 1
someone
  • 6,577
  • 7
  • 37
  • 60