Re: Connecting to more than 2 databases from a single PHP script.

From: Date: Mon, 20 Aug 2007 15:20:42 +0000
Subject: Re: Connecting to more than 2 databases from a single PHP script.
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-43920@lists.php.net to get a copy of this message
You can still use PDO in order to access as many databases you need using different handlers. This is a way for e.g. $dbhost1 = 'localhost'; $dbuser1 = 'test'; $dbpass1 = '12345'; $db1 = 'database_name'; $dbh1 = new PDO('mysql:host='.$dbhost1.';dbname='.$db1, $dbuser1, $dbpass1); $dbhost2 = 'database.example.net'; $dbuser2 = 'test'; $dbpass2 = '12345'; $db2 = 'database_name'; $dbh2 = new PDO('mysql:host='.$dbhost2.';dbname='.$db2, $dbuser2, $dbpass2); You can query the database buy doing:
          $sth = $dbh->prepare($query);
          $sth->execute();
Have in mind that mysql is not the only option you have but you should check the documentation for more info. http://www.php.net/manual/el/ref.pdo.php Chris wrote:
Suamya Srivastava wrote:
Hello, In a single PHP code, I want to connect to two mysql databases with totally different authentication information. Is it possible?
See http://php.net/mysql_connect - you need to set 'new_link' to true in the mysql_connect call.


« previous php.db (#43920) next »