Here’s my situation. I got one site up that has a mysql database, works fine… Now I purchased a new domain name and am trying to use the same database for the new site. Any idea’s on what the host would be?
For my other site I use
$host = “localhost”;
But that doesn’t seem to work any ideas on what would work?
How Do I Connect To Mysql With Php Remotely?
December 19th, 2009 by CTO WebOjO.com website designers Lahore Pakistan Leave a reply »
Advertisement
Two things:
- Find the Full Domain name of the first domain. It might be something complex, so you might have to send a support email to the hosting company;
- Make sure you allow remote connections from your second machine: many hosts block all connections to MySQL except from Localhost. If you have access to CPanel, there is an option to add additional hosts that can connect to your MySQL server (add you second host).
Good luck!
If the domains aren’t on the same server, which seems to be the case if localhost doesn’t work, you’ll need to use the database server’s IP address. If you don’t know your IP off-hand, you can get it by typing “ping your-domain.com” at a command prompt and you’ll see the IP address for your domain.
The remote MySQL server would also need to be configured to allow a remote connection, most shared hosts aren’t setup for this so you may run into issues.
You will have to use the FQDN, eg:
$db = mysql_connect(”example.com”,”usename”,”p…
$dbname = “db name”;
Some hosts do not allow you to connect from a remote site, the site has to be on the same server of hosting company. Check CPanel and see if it’s even available.