-2

I was wondering how i can connect to multiple databases on a single PHP webpage. i know how to connecet to a single database using:

enter code here:
               $dbh=mysql_connect($hostname,$username,$password)or die("unable to connect to MYSQL");

However,can i just use multiple "mysql_connect"commands to open the other databases,and how would PHP know what databases i want the informaion pulled from if I do have multiple databases connected

  • And as always the hint: the old and outdated mysql connector has been deprecated quite a while now. It is not part of php7 any more. One should not use it any more, one should not implement new code based on it. That all is _clearly_ documented. Move to `mysqli` or `PDO`. You will also gain more safety if you do that right. – arkascha Sep 25 '16 at 18:46
  • Stop using the **deprecated and as of PHP7 removed** `mysql_*` functions. Migrate to PDO and start using Prepared Statements. – Charlotte Dunois Sep 25 '16 at 18:49
  • There is a dupe target for your `mysql_`. But time to get onto the `mysqli` or `PDO` bandwagon – Drew Sep 25 '16 at 18:51

1 Answers1

1

You can use multiple variables to point at different database connections. Just call the connect and assign the handle to another variable.

M.Alnashmi
  • 582
  • 1
  • 4
  • 15