[PHP] 2 x DB connections at once

2004-01-23 Thread Donald Tyler
Yes thanks, that will do it. I wasn't aware you had to pass an extra param
to get it to create a new connection.

Both the connections were in separate objects and they were being specified
every time I did a query or select db, but since I didn't add that extra
param you mentioned I guess they were really the same connection even though
they were two separate private variables in different objects.

Thanks for your help

-Original Message-
From: Luke [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 22, 2004 4:22 PM
To: Donald Tyler
Subject: Re: [PHP] 2 x DB connections at once

It depends, how are you creating the connections, and where are you keeping
the connection ID
and when you query, or select database, or anything to do with the
databases, do you make sure you specify that connection id?

//Notice the TRUE, that creates a new conenction, and doesnt use the
existing connection (hence returning a different id)

$sqlconnection1 = mysql_connect('test.com', 'username', 'password');
$sqlconnection2 = mysql_connect('test.com', 'username', 'password', TRUE);

then when you select databases and query youll have to specify that
connection!

//choose DB 1 on connection 1
mysql_select_db('mydata1', $sqlconnection1);
//choose db2 on connetion 2
mysql_select_db('mydata1', $sqlconnection2);

//and querying
//this will select the table named table from the mydata1 database
mysql_query(SELECT * FROM table WHERE name='me', $sqlconnection1);
//this will select the table named table from the mydata2 database
mysql_query(SELECT * FROM table WHERE name='me', $sqlconnection2);


hope thats what you were after
-- 
Luke

_
Donald Tyler [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
OK, now I have done some work and it gets even stranger.

Two Objects

Validator
Importer

Both objects have private variables called $this-Connection

However, when I change the DB for one objects connection pointer, the other
objects connection pointer ALSO changes DB.

Is it not possible to have two completely separate DB connections active at
the same time?


-Original Message-
From: Donald Tyler [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 22, 2004 3:08 PM
To: [EMAIL PROTECTED]
Subject: [PHP] 2 x DB connections at once

I thought this was possible, but it doesn't seem to be working:

I have a class, that has a private variable called $this-Connection, which
is a Database Connection pointer to a MySQL database. During the lifetime of

the Class, it uses the connection multiple times without a problem.

The class also uses a function from an include file that has its OWN
Database Connection pointer. And it seems that for some reason, as soon as
that external function is called, the Private Database Pointer within my
Class suddenly points to the Database name that the external functions
Database Pointer was using.

I ALWAYS specify which connection pointer I want to use when selecting the
DB and doing a mysql_query, so I have no earthly idea how the external
Connection pointer is affecting my Private Connection Pointer.

I hope I explained that well enough; it's real difficult to put into words.

Does anyone have any idea what might be happening?

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

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



[PHP] 2 x DB connections at once

2004-01-22 Thread Donald Tyler
I thought this was possible, but it doesn't seem to be working:

I have a class, that has a private variable called $this-Connection, which
is a Database Connection pointer to a MySQL database. During the lifetime of
the Class, it uses the connection multiple times without a problem.

The class also uses a function from an include file that has its OWN
Database Connection pointer. And it seems that for some reason, as soon as
that external function is called, the Private Database Pointer within my
Class suddenly points to the Database name that the external functions
Database Pointer was using.

I ALWAYS specify which connection pointer I want to use when selecting the
DB and doing a mysql_query, so I have no earthly idea how the external
Connection pointer is affecting my Private Connection Pointer.

I hope I explained that well enough; it's real difficult to put into words.

Does anyone have any idea what might be happening?

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



RE: [PHP] 2 x DB connections at once

2004-01-22 Thread Donald Tyler
OK, now I have done some work and it gets even stranger.

Two Objects

Validator
Importer

Both objects have private variables called $this-Connection

However, when I change the DB for one objects connection pointer, the other
objects connection pointer ALSO changes DB.

Is it not possible to have two completely separate DB connections active at
the same time?


-Original Message-
From: Donald Tyler [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 22, 2004 3:08 PM
To: [EMAIL PROTECTED]
Subject: [PHP] 2 x DB connections at once

I thought this was possible, but it doesn't seem to be working:

I have a class, that has a private variable called $this-Connection, which
is a Database Connection pointer to a MySQL database. During the lifetime of
the Class, it uses the connection multiple times without a problem.

The class also uses a function from an include file that has its OWN
Database Connection pointer. And it seems that for some reason, as soon as
that external function is called, the Private Database Pointer within my
Class suddenly points to the Database name that the external functions
Database Pointer was using.

I ALWAYS specify which connection pointer I want to use when selecting the
DB and doing a mysql_query, so I have no earthly idea how the external
Connection pointer is affecting my Private Connection Pointer.

I hope I explained that well enough; it's real difficult to put into words.

Does anyone have any idea what might be happening?

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

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



Re: [PHP] 2 x DB connections at once

2004-01-22 Thread Luke
It depends, how are you creating the connections, and where are you keeping
the connection ID
and when you query, or select database, or anything to do with the
databases, do you make sure you specify that connection id?

//Notice the TRUE, that creates a new conenction, and doesnt use the
existing connection (hence returning a different id)

$sqlconnection1 = mysql_connect('test.com', 'username', 'password');
$sqlconnection2 = mysql_connect('test.com', 'username', 'password', TRUE);

then when you select databases and query youll have to specify that
connection!

//choose DB 1 on connection 1
mysql_select_db('mydata1', $sqlconnection1);
//choose db2 on connetion 2
mysql_select_db('mydata1', $sqlconnection2);

//and querying
//this will select the table named table from the mydata1 database
mysql_query(SELECT * FROM table WHERE name='me', $sqlconnection1);
//this will select the table named table from the mydata2 database
mysql_query(SELECT * FROM table WHERE name='me', $sqlconnection2);


hope thats what you were after
-- 
Luke

_
Donald Tyler [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
OK, now I have done some work and it gets even stranger.

Two Objects

Validator
Importer

Both objects have private variables called $this-Connection

However, when I change the DB for one objects connection pointer, the other
objects connection pointer ALSO changes DB.

Is it not possible to have two completely separate DB connections active at
the same time?


-Original Message-
From: Donald Tyler [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 22, 2004 3:08 PM
To: [EMAIL PROTECTED]
Subject: [PHP] 2 x DB connections at once

I thought this was possible, but it doesn't seem to be working:

I have a class, that has a private variable called $this-Connection, which
is a Database Connection pointer to a MySQL database. During the lifetime of

the Class, it uses the connection multiple times without a problem.

The class also uses a function from an include file that has its OWN
Database Connection pointer. And it seems that for some reason, as soon as
that external function is called, the Private Database Pointer within my
Class suddenly points to the Database name that the external functions
Database Pointer was using.

I ALWAYS specify which connection pointer I want to use when selecting the
DB and doing a mysql_query, so I have no earthly idea how the external
Connection pointer is affecting my Private Connection Pointer.

I hope I explained that well enough; it's real difficult to put into words.

Does anyone have any idea what might be happening?

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

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



Re: [PHP] 2 x DB connections at once

2004-01-22 Thread Justin Patrin
You're running into an old error. I believe that this was a problem with 
previous versions of PHP, are you using the newest version?

Barring that, if you add true to the end of the mysql_connect call to 
make it a different connection, that should also fix things.

Or you could try using PEAR::DB or one of the other DB abstraction 
classes which will take care of all of that for you.

http://pear.php.net/package/db

Donald Tyler wrote:

OK, now I have done some work and it gets even stranger.

Two Objects

Validator
Importer
Both objects have private variables called $this-Connection

However, when I change the DB for one objects connection pointer, the other
objects connection pointer ALSO changes DB.
Is it not possible to have two completely separate DB connections active at
the same time?
-Original Message-
From: Donald Tyler [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 22, 2004 3:08 PM
To: [EMAIL PROTECTED]
Subject: [PHP] 2 x DB connections at once

I thought this was possible, but it doesn't seem to be working:

I have a class, that has a private variable called $this-Connection, which
is a Database Connection pointer to a MySQL database. During the lifetime of
the Class, it uses the connection multiple times without a problem.
The class also uses a function from an include file that has its OWN
Database Connection pointer. And it seems that for some reason, as soon as
that external function is called, the Private Database Pointer within my
Class suddenly points to the Database name that the external functions
Database Pointer was using.
I ALWAYS specify which connection pointer I want to use when selecting the
DB and doing a mysql_query, so I have no earthly idea how the external
Connection pointer is affecting my Private Connection Pointer.
I hope I explained that well enough; it's real difficult to put into words.

Does anyone have any idea what might be happening?



--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php