Postgres Remote Database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

Postgres Remote Database

Post by phppick »

Hi,

I have Two databases names 'MyDb1' and 'MyDb2' in My System.

I have installed Postgres 7.4 with dblink

What i need is, when ever a NEW record is inserted in 'MyDb1' , i want fire a Trigger or Rule to insert the Same Record to MyDb2 database.

I am Using MAC OS 10.2

Anybody Got Idea how to do this?

Thanks

[pg_man][/pg_man]

----------------------------------------------
Some Sample Query Using "dblink" is:
select * from dblink('hostaddr=192.168.1.1 dbname=MyDb1 user=pgsql','select username,password,usertype from users') as t1(username varchar,password varchar,usertype varchar);

----------------------------------------------
jaxn
Forum Commoner
Posts: 55
Joined: Fri Jan 16, 2004 1:50 pm
Location: Nashville, TN

Post by jaxn »

Are you wanting to replicate the entire database or just on a few insert statements?

-JAckson
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

Mr. Jason

Post by phppick »

Hi ,

I just want to do it on One table. Ie
When ever a new is inserted in DB 'MyDb1.users' i want to insert the same record in 'MyDb2.users' tables as well
jaxn
Forum Commoner
Posts: 55
Joined: Fri Jan 16, 2004 1:50 pm
Location: Nashville, TN

Post by jaxn »

It looks like you are trying to allow users who sign up on one site have an account on another account as well. Is this right?

you could have the signup script connect to both databases and insert into both databases. You would connect to two databases with something like:

Code: Select all

<?php
$db1 = mysql_connect('localhost','user1','pass1');
$db2 = mysql_connect('some.other.host.com','user2','pass2');
?>
Then you would do an insert to db1 and another insert to db2. However, this method requires that at least on of the databases servers is available via TCP/IP.

Another method would be an automated export/import process. Connecting to two hosts would be easier though.

-Jackson
Post Reply