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

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

am 16.08.2007 08:25:18 von Suamya Srivastava

Hello,

In a single PHP code, I want to connect to two mysql databases with
totally different authentication information. Is it possible?

Right now snippet of my code looks something like this:
......
$conn_1=mysql_connect('host1','user1','pass1');
$conn_2=mysql_connect{'host2','user2','pass2');
$db_list = mysql_list_dbs($conn_2);

while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}
?>

However when I try to list all the databases in host2, it instead lists
the database in host1.
host1 and host2 are different machines and the databases in each of them
are entirely different.

I read that the new_link parameter might be used here but I couldnt figure
out how to do that.

I am new to PHP...so any help would be great!!

-suamya.

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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

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

am 16.08.2007 08:44:48 von dmagick

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.

--
Postgresql & php tutorials
http://www.designmagick.com/

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

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

am 20.08.2007 17:20:42 von Goltsios Theodore

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.
>

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

Drop and Down with PHP/Postgre

am 21.08.2007 11:59:36 von Celso Page

Hi All,

I would like to know how can I do the form with box with drop and down using
PHP/Postgre.

Thank you very much

Celso Page

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

Re: Drop and Down with PHP/Postgre

am 22.08.2007 02:02:16 von dmagick

Celso Page wrote:
> Hi All,
>
> I would like to know how can I do the form with box with drop and down
> using PHP/Postgre.

Same as anything else really. Get your data, loop over it and construct
a dropdown field.

Which part are you having troubles with?

--
Postgresql & php tutorials
http://www.designmagick.com/

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

Re: Drop and Down with PHP/Postgre

am 22.08.2007 04:26:27 von Celso Page

Hi Chris,

I follow your steps and works. But now I have another trouble , I would to
use this field to populate another table using this form.

Is it possible ?

Thank you very much,

Celso Page



----- Original Message -----
From: "Chris"
To: "Celso Page"
Cc:
Sent: Tuesday, August 21, 2007 9:02 PM
Subject: Re: [PHP-DB] Drop and Down with PHP/Postgre


> Celso Page wrote:
>> Hi All,
>>
>> I would like to know how can I do the form with box with drop and down
>> using PHP/Postgre.
>
> Same as anything else really. Get your data, loop over it and construct a
> dropdown field.
>
> Which part are you having troubles with?
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
> --
> 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