Re: Two MySQL connections in one script not working as expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

Without you actually showing us these class files we can only guess but a 
common mistake is this:

mysql_open(connection details)
mysql_query(query)

In those cases the last opened handle is used.  To prevent this, use this 
syntax

$db1=mysql_open(connection for db1);
$db2=mysql_open(connection for db2);

mysql_query($db1,$query_db_1);
mysql_query($db2,$query_db_2);

If you have used this syntax then check your class if it is using a global 
variable to hold the database handle and if it does make it a class variable 
instead

Instead of 

$db=null

class db
{function db()
 {$GLOBALS['db']=mysql_open(...

do instead

class db
{var $db=null;
 function db()
 {$this->db=mysql_open

That way you can instanciate as many instances of the class as you like and 
each will have its own database handle.

HTH


Andy

On Tuesday 27 September 2005 20:25, Charles Kline wrote:
> Hi all,
>
> I have a script that needs to update data in two databases. My db
> connections are both in class files that I created to execute the
> various connections and queries.
>
> What is happening is that the second database connection does not
> seem to work. The error I get is that it seems the second query is
> being executed against the first database connection - does that make
> sense? So I get an error that the database_name.table_name does not
> exist, which is true, but the query is getting executed against the
> wrong database name.
>
> Any ideas?
>
> Thanks,
> Charles

-- 
Registered Linux User Number 379093
Now listening to Radio Stream

   amaroK::the Coolest Media Player in the known Universe!


   Cockroaches and socialites are the only things that can 
   stay up all night and eat anything.
					    Herb Caen
--
-- --BEGIN GEEK CODE BLOCK-----
Version: 3.1
GAT/O/>E$ d-(---)>+ s:(+)>: a--(-)>? C++++$(+++) UL++++>++++$ P-(+)>++
L+++>++++$ E---(-)@ W+++>+++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++)
PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+)
e>++++$@ h++(*) r-->++ y--()>++++
-- ---END GEEK CODE BLOCK------
--
Check out these few php utilities that I released
 under the GPL2 and that are meant for use with a 
 php cli binary:
 
 http://www.vlaamse-kern.com/sas/

--

Attachment: pgpDdyEPG6y49.pgp
Description: PGP signature


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux