473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Two mysql connections

Not really tried going two ways at once, but I have an include_once
connection to a mysql_database, now I need to retrieve info from a second
mysql_database ..

My mysql_connects are getting confused. So, (I've had a couple of beers), am
I opening up too many at once?

I'll look again in the morning, but am thinking that it is a bad idea to
leave two connections open all the time ...

Anyone able to advise?

Thanks

Jun 13 '06 #1
4 6042
>Not really tried going two ways at once, but I have an include_once
connection to a mysql_database, now I need to retrieve info from a second
mysql_database ..
Connections aren't include_once. You may be including the code to make
the connection with include_once, but that doesn't affect the connection.
My mysql_connects are getting confused. So, (I've had a couple of beers), am
I opening up too many at once?
No. I had a page that opened up 3 connections (in this case, on 3
different servers) to compare the data on the 3 servers. Essentially,
it was a test for a data migration script (which also involved a
lot of reorganization) to check if anything got missed. It proved
very useful. Performance and simultaneous use weren't issues, and
only I used it.

You should pass the correct connection handle (er, "resource") to
all of the mysql_* functions to indicate which one you wish to use,
including mysql_query, mysql_select_db, and functions to fetch
results. If you don't pass the connection handle, PHP will pick
one (I forget whether it's the first or the latest), and Murphy's
law says it gets the wrong one more than 50% of the time.
I'll look again in the morning, but am thinking that it is a bad idea to
leave two connections open all the time ...


Leaving two connections open during processing a PHP page is not
"all the time" unless you've got a heck of a lot of traffic.

Persistent connections tend to accumulate a large number of idle
connections, perhaps more than the server can handle. You also
tend to end up with the MAXIMUM number of connections (as set in
Apache by child_max) rather than the average number of simultaneous
connections actually being used).

Assuming, for the moment, that generating the PHP page takes less
than, say, 1 minute, you should hold the connections for as long
as you need them rather than disconnecting and re-connecting. That's
probably the whole time unless you are doing complicated manipulation
of the data after you fetch it before presenting it. If it takes
longer than that, how do you put up with that poor response?

Gordon L. Burditt
Jun 14 '06 #2

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:12*************@corp.supernews.com...
Not really tried going two ways at once, but I have an include_once
connection to a mysql_database, now I need to retrieve info from a second
mysql_database ..


Connections aren't include_once. You may be including the code to make
the connection with include_once, but that doesn't affect the connection.
My mysql_connects are getting confused. So, (I've had a couple of beers),
am
I opening up too many at once?


No. I had a page that opened up 3 connections (in this case, on 3
different servers) to compare the data on the 3 servers. Essentially,
it was a test for a data migration script (which also involved a
lot of reorganization) to check if anything got missed. It proved
very useful. Performance and simultaneous use weren't issues, and
only I used it.

You should pass the correct connection handle (er, "resource") to
all of the mysql_* functions to indicate which one you wish to use,
including mysql_query, mysql_select_db, and functions to fetch
results. If you don't pass the connection handle, PHP will pick
one (I forget whether it's the first or the latest), and Murphy's
law says it gets the wrong one more than 50% of the time.


Firstly, thanks for the really prompt reply!

Okay, this is where I am making a mistake.

I have two files that use the same code ... i.e.

<?php
$dbhost = "server1.com";
$dbname = "server1_dbname";
$dbuser = "server1_dbuser";
$dbpass = "123";

$link=mysql_connect ("$dbhost", "$dbuser", "$dbpass") ;
@mysql_select_db ("$dbname");
?>

I now have a second file called connecttodb.php which has same info, but
different server (i.e. all db stuff is different).

How should I differentiate between the two files when doing calling the
database? i.e. should I call SELECT * FROM file1.tablename etc?

Thanks

Nick

Jun 14 '06 #3
><?php
$dbhost = "server1.com";
$dbname = "server1_dbname";
$dbuser = "server1_dbuser";
$dbpass = "123";

$link=mysql_connect ("$dbhost", "$dbuser", "$dbpass") ;
You see that value $link returned by mysql_connect?
It's a connection handle. Or, if you prefer, a resource link_identifier.
@mysql_select_db ("$dbname");
You pass the connection handle to functions that use the connection, like:

mysql_select_db("$dbname", $link);
?>

I now have a second file called connecttodb.php which has same info, but
different server (i.e. all db stuff is different).
Hopefully it assigns to something different from $link (like $link2).
How should I differentiate between the two files when doing calling the
database? i.e. should I call SELECT * FROM file1.tablename etc?


$resultset = mysql_query("SELECT * FROM tablename", $link2);

Those optional link_identifier arguments aren't optional in your situation.

Gordon L. Burditt
Jun 14 '06 #4

"Gordon Burditt" <go***********@burditt.org> wrote in message
news:12*************@corp.supernews.com...
Hopefully it assigns to something different from $link (like $link2).
Thanks, I've decided to use more clear names :)
How should I differentiate between the two files when doing calling the
database? i.e. should I call SELECT * FROM file1.tablename etc?
$resultset = mysql_query("SELECT * FROM tablename", $link2);


Absolutely spot on. Not something I've needed to have do before now, as all
my databases have been stored in the same place. Now I am needing to keep a
central database for different projects ...

!! Your advice has been very useful! !!
Those optional link_identifier arguments aren't optional in your
situation.


:)

Thanks again ....

Nick
Jun 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Titus Cheung | last post by:
Hello, Thought I read somewhere saying that there is a limit to how many connections are available per mySQL account or something like that. Can someone please clarify? I wrote a PHP tool...
0
by: I.P. | last post by:
Hi, it's my story. I have two 4.0.14 mysql server on one machine with win XP Professional polish version. First acts as master: on port 3300 Second acts as slave: on port 3301 below my...
0
by: I.P. | last post by:
No one has replied to my post. ----- Original Message ----- From: "I.P." <jancio_wodnik@wp.pl> To: <mysql@lists.mysql.com> Sent: Monday, August 18, 2003 1:01 PM Subject: mysql 4.0.14 +...
16
by: MLH | last post by:
Using MS Access, I have attached to MySQL servers in other states and other countries on the other side of my router. But when I use the MySQL ODBC driver 3.51 to connect to a MySQL server on my...
3
by: Anthony | last post by:
Hey all, Here's a question for you, my hosts have told me that that one my pages, php, was causing their server to reboot because there were too many open connections and that they should be...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
4
by: Richard | last post by:
Hi All, I've been trying to build a Ruby-on-Rails plus MySQL application. I'm running Ruby 1.8.2, Rails 1.1.4 and MySQL 5.0.15-nt over WinXP-Pro/SP2. I run under an Administrative account. ...
1
by: marcfischman | last post by:
Please help. I have a website running on a linux/apache/mysql/php server. I receive about 8,000-10,000 visitors a day with about 200,000 to 300,000 page views. The server is a RedHat Linux...
3
by: rockdale | last post by:
Hi, all: My web application using MS EntLib for .net 2.0 (Jan 2006) to access my backend database. It works fine with MS SQL 2k. Now we are migrate from MS SQL to mySQL. Everything looks fine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.