RE: [PHP-DB] Multiple Database Connection Using Prepard Statements

2012-05-20 Thread Gavin Chalkley
Just remember to close the correct connection whn it is time to :)

-Original Message-
From: Matijn Woudt [mailto:tijn...@gmail.com] 
Sent: 19 May 2012 23:42
To: Ron Piggott
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Multiple Database Connection Using Prepard Statements

On Sat, May 19, 2012 at 8:36 PM, Ron Piggott ron.pigg...@actsministries.org 
wrote:

 How do I connect to multiple mySQL databases using Prepared Statements ?

 I have the syntax

 ===
 $dsh = 'mysql:host=localhost;dbname='.$database3;
 $dbh = new PDO($dsh, $username, $password); ===

 I want to connect to $database1 without loosing my $database3 
 connection


$dsh = 'mysql:host=localhost;dbname='.$database3;
$dbh = new PDO($dsh, $username, $password);
$dsh2 = 'mysql:host=localhost;dbname='.$database1;
$dbh2 = new PDO($dsh2, $username2, $password2);

Now you can use $dbh for $database3, and $dbh2 for $database1...

- Matijn

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Multiple Database Connection Using Prepard Statements

2012-05-20 Thread Bastien


Bastien Koert

On 2012-05-19, at 2:36 PM, Ron Piggott ron.pigg...@actsministries.org wrote:

 
 How do I connect to multiple mySQL databases using Prepared Statements ?
 
 I have the syntax
 
 ===
 $dsh = 'mysql:host=localhost;dbname='.$database3; 
 $dbh = new PDO($dsh, $username, $password); 
 ===
 
 I want to connect to $database1 without loosing my $database3 connection
 
 Thoughts?  Comments?  
 
 
 Ron Piggott
 
 
 www.TheVerseOfTheDay.info 

Ron,

MySQL also supports the convention of using the database name in the query so 
that you don't necessarily need another connection manage

Select field1, field2 ... Fieldn from db2.table_name [where clause]



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Multiple Database Connection Using Prepard Statements

2012-05-19 Thread Peter Lind
On 19 May 2012 20:36, Ron Piggott ron.pigg...@actsministries.org wrote:

 How do I connect to multiple mySQL databases using Prepared Statements ?

 I have the syntax

 ===
 $dsh = 'mysql:host=localhost;dbname='.$database3;
 $dbh = new PDO($dsh, $username, $password);
 ===

 I want to connect to $database1 without loosing my $database3 connection

 Thoughts?  Comments?


Create a new PDO object with the connection details you need?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Multiple Database Connection Using Prepard Statements

2012-05-19 Thread Matijn Woudt
On Sat, May 19, 2012 at 8:36 PM, Ron Piggott
ron.pigg...@actsministries.org wrote:

 How do I connect to multiple mySQL databases using Prepared Statements ?

 I have the syntax

 ===
 $dsh = 'mysql:host=localhost;dbname='.$database3;
 $dbh = new PDO($dsh, $username, $password);
 ===

 I want to connect to $database1 without loosing my $database3 connection


$dsh = 'mysql:host=localhost;dbname='.$database3;
$dbh = new PDO($dsh, $username, $password);
$dsh2 = 'mysql:host=localhost;dbname='.$database1;
$dbh2 = new PDO($dsh2, $username2, $password2);

Now you can use $dbh for $database3, and $dbh2 for $database1...

- Matijn

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php