PDA

View Full Version : php mysql connection from different sites(hosts)



amitbravo
04-11-2007, 10:43 AM
I have mysql database on www.ravedir.com but i want to access this database from another site www.ravehealthdirectory.com

I do not know how to connect database like this .. i am sure i do not have to use "localhost" but what ?.

Both sites have shared IP address ( do i need to have unique IP address for www.ravedir.com ?) both sites are hosted on linux server with cpanel.


I tried lot of things like this :

mysql_connect("ravedir.com:2082",$user,$pass) or die (mysql_error());
$query=mysql_select_db($database);
mysql_query($query);

even used IP addresses , there is an option in cpanel based linux hosting where you can allow access host adding their name server e.g. ns1.name-services.com .. but failed

visit to http://au.php.net/function.mysql-connect using example.com:3307 as a port .

How could I know about my port exactly.

though i am familiar to php for last few months but hard to me to configure php on server ...


looking forward to hearing soon
kindest regards,
amit

Valentin
04-13-2007, 06:17 AM
MySQL service on all our servers works on port 3306.

You can connect to your MySQL database remotelty by using the following hostname:

MySQL host: servername.com or serverip
MySQL port: 3306
MySQL user: You have to create one via the cPanel -> MySQL database -> Create user tool
MySQL pass: replace_this
MySQL db: You can create your DB from your cPanel -> MySQL database

Please make sure that you have granted previlegies for the user created above to your MySQL database. You can easily do this by adding the username to the database. See:

http://www.siteground.com/tutorials/cpanel/mysql.htm

You can try with:

$dbh=mysql_connect ("REPLACE_THIS_WITH_YOUR_SERVER_NAME", "YOUR_MYSQL_USERNAME", "PASSWORD_HERE") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("YOUR_MYSQL_DATABASE_NAME");

If you want to access your database remotely please make sure that you have added the IP address of the PC/server you are accessing your MySQL DB from to the list of allowed hosts:

cPanel -> MySQL databases -> Allowed hosts at the bottom of the page -> Add host.