jiulian jef Curato
jiulian jef Curato

Reputation: 11

Accessing my other database from my website 1 to my website 2

I have website 1 currently uploaded in the web and i have also develop a website 2 running on the localhost for now.. I want to access or get some value from the website 1 database to my website 2..is this possible using php query or javascripting? if not, what approach i need to take? thanks for the help

Upvotes: 1

Views: 118

Answers (3)

Airful
Airful

Reputation: 311

Yes, It's simple.

<?php
$hostname = "remote_host_name";
$database = "remote_database_name";
$username = "database_username";
$password = "database_password";

$con = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $con);
?>

Use this $con as the second parameter while running query.

e.g. mysql_query($query, $con);

Make sure that you have granted the access of server 1 in server 2 mysql database.

Upvotes: 0

Geert
Geert

Reputation: 1227

To allow connections from an external IP-address, you will need to do the following as well:

Grant access to a new database

If you want to add a new database called foo for user bar and remote IP 202.54.10.20 then you >need to type the following commands at mysql> prompt:

mysql> CREATE DATABASE foo;

mysql> GRANT ALL ON foo.* TO bar@'202.54.10.20' IDENTIFIED BY 'PASSWORD';

More information

Upvotes: 0

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

Yes you can, You have to just pass the parameters of the server details like this example.

<?php
//Connect To Database
$hostname='ukld.db.5510597.hostedresource.com';
$username='myusername';
$password='mypassword';
$dbname='testdb';
//your rest of code
?>

Upvotes: 1

Related Questions