Matt Ridge
Matt Ridge

Reputation: 3651

How to access two databases, one to input, another to publish simultaneously in PHP?

Ok, I am looking to use php to access two databases.

The form posts into database 1 (person), while I have in the form two drop down menus that access a second database named (pulldown) to populate themselves.

So it would look like this.

  1. First Name:
  2. Last Name:
  3. Title (Pull down menu from second database)
  4. 401k?:

Now I know to access one database you need to enter in

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)

How does it work when you need to access two of them?

Now the pull down code isn't an issue, but it is when it is inserted into a form like what I want, how I want to do it, it is.

Can anyone here help?

So what I want is to have access to person and pulldown at the same time, even though data is being pulled from pulldown and entered into person.

Does this make any sense?

Upvotes: 1

Views: 225

Answers (1)

Timur
Timur

Reputation: 6718

$dbc1 = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME1);
$dbc2 = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME2);

// ... some code ...

mysqli_query($dbc1,$query1);
mysqli_query($dbc2,$query2);

Upvotes: 1

Related Questions