tags:

views:

69

answers:

4

Hi,

I am trying to connect to the database that is hosted on my server through my local machine.

my server has cPanel 11, and it is a typical shared server, powered by CentOS, PHP and MySQL installed.

to be precise i am holding the reseller account in the same server. i want to access the database between different accounts or domains.

in MySQL connection String i tried defining the domain name, and it isn't working. here is what i tried.

<?php
$link = mysql_connect('mydomain.com', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

this is giving the following error

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://bhatkalnews.com:3306) in C:\wamp\www\test\conn.php on line 4

Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\test\conn.php on line 4

Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\test\conn.php on line 4

what do i have to define in connection string to make it work?

+1  A: 

Did you try adding the port explicitly:

mysql_connect('mydomain.com:3306', 'mysql_user', 'mysql_password');

or the port youre running on if not the default 3306. This of course assumes your server allows remote connections.

Also make sure the user in quest has access from the IP address youre connecting from. This isnt youre issue right now, but it may be the next question you have after you get the server to respond :-)

prodigitalson
i tried adding the port 3306 and it is not working.
Ibrahim Azhar Armar
+1  A: 

Please refer,

http://forums.mysql.com/read.php?52,294772

Yogesh
@IBrahim. Kinda rude comment, Yogesh is trying to help here, that forum might have clues
Ben
sorry @Ben and my apology to Yogesh. i deleted the comment.
Ibrahim Azhar Armar
A: 

You need to add your IP address/range on Access Host list in Remote MySQL in cPanel.

Ruel
i did that. it isn't working still :(
Ibrahim Azhar Armar
Ok, can you go to cPanel, then phpMyAdmin, and check the server name. Some shared web hosts use different mysql servers. If it's not localhost, then its not on the server your website is on.
Ruel
Port `3306` on `bhatkalnews.com` is closed. It must be a different server, or a different port.
Ruel
@Ruel Server is the same, how do i know which port is open in my server?
Ibrahim Azhar Armar
+2  A: 

Firewall ?

try

telnet mydomain.com 3306

on the command line.

If that doesn't work, the connection is blocked by a firewall, most likely

Ben
@Ben i tried the command and it says Connect failed. how can the connection be blocked by a firewall if i can access the same through normal http request?
Ibrahim Azhar Armar
accessing mydomain.com through http means you're connecting to port 80, that port is likely open (it's the standard web port). Port 3306 used by mysql is likely blocked to the outside world. You'd need to contact your web hosting company and ask them to open it.. and they likely won't.
Ben
lol, is their any other alternative then?
Ibrahim Azhar Armar
the question is why do you need your local dev machine to access the live server directly? seems like a bad idea. You should work on your local dev mysql database and push changes to the live server (using phpMyAdmin for instance) only when things are good to go live
Ben
@Ben correct, i don't want to access it directly. but what i am trying to do is. i hold a reseller account with a hosting company. and i am designing the website for someone. they have multiple domains and accounts within the same server and want to access the data across the domain that is stored in the database. the reason i wanted the string for my local machine is just to check if it works or not.
Ibrahim Azhar Armar
Confusing...If you mean the multiple domains accessing each other's database, it will work *from within the live server's network*If you mean giving the client access to the databases, they can use phpMyAdmin from the account you give them with your reseller account
Ben
@Ben i can access the database from within the server. even i got confused. thank you for correcting me :)
Ibrahim Azhar Armar