简体   繁体   中英

Access data and reference ID from a table in another MySQL database or?

I have a mysql database for form submission (written in PHP) data and a mysql database for crm (using X2CRM) on the same server.

When a form is submitted on my website the POSTed data of the form will be sent to emails as notifications to customers signed up a contract. These emails are of customers stored in the crm database.

I would like to reference customer IDs as a FK with the form submission id on a table in the form submission database.

Is it better to directly access the CRM database with SQL and get insert the customer id accordingly on the form submission table DB as explained here http://wiki.x2engine.com/wiki/Interacting_with_the_Database

I would query and use only the customer IDs that have contract status set to active.

Or should I maintain a table in the form submission DB with the required information of the customers (such as name, address email, contract status)? That would obviously mean overhead to maintain the data with the one in CRM?

So best to go with first option? But is it ok to use PK IDs from one DB as FKs in a table on another DB?

I guess with first option I will need to query the CRM database and use the relevant values (ID and email address) for each customer record everytim a form is submitted? What should be the efficient and recommended way to do this?

I think you should go for the first options, therefor you avoid duplicating unnecessary data and maintain it. and you should add foreign key in the submission table that references to the CRM's customer table

create table submission (
  id .......
  crm_customer_id int unsigned not null,
  ......
  foreign key(crm_customer_id) references crm.customer_id on update cascade on delete cascade,
  .....
) engine=InnoDB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM