473,769 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6065
>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_databa se ..
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.supe rnews.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_databas e ..


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.co m";
$dbname = "server1_dbname ";
$dbuser = "server1_dbuser ";
$dbpass = "123";

$link=mysql_con nect ("$dbhost", "$dbuser", "$dbpass") ;
@mysql_select_d b ("$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.co m";
$dbname = "server1_dbname ";
$dbuser = "server1_dbuser ";
$dbpass = "123";

$link=mysql_co nnect ("$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("SE LECT * 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.supe rnews.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("SE LECT * 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
8956
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 that uses a different PHP file whenever someone hit an HTML form button (ie Submit). It turned out that each one of these PHP files need to re-open the link to the mySQL database by the following snippet or else that particular file won't work:
0
3264
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 configuration:
0
2146
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 + replication + windows XP PROF Hi, it's my story.
16
27923
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 own LAN, the driver tells me it cannot make the connection. Here are the ODBC driver connection parms: Data Source Name: (free field - name my "my linux box" will do nicely) Host/Server Name (or IP) - something like MSQLUserName@ServerName.net...
3
2236
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 closed. Now, correct me if I am wrong but I thought that the connections were closed after a minute of inactivity. Does this sound right? Could open connections cause their server to reboot a
1
3379
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 uses his own php shopping cart to receive customer orders. The configuration was done via cPanel with no external modifications - which produced no protests when built, ran and connected with no
1
2829
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. Despite entering the required lines to "my.ini" (the new my.cnf) through notepad AND MySQL Administrator, the cache does not work. So, today I took a peek at the 'Health' tab in MySQL Administrator.
4
5364
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. I tried building the first example from Agile Web Development with Rails, 1st ed. Somehow the DB got corrupted and I couldn't recover. Instead of retrying that, I tried building the first example from Ruby For Rails, which worked fine.
1
13683
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 server running PHP 5.x, MySQL 5.x, Apache 2.x We have been suffering from a number of performance issues. Our hosting company has set our max connections to 100, and we are using persistent connections in PHP. At times the mysqld process takes 100%...
3
3576
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 except one serious problem: we got the "too many connections" error. Looks like the EntLib did not properly close these connections. on mySQL Administratorserver connectionsThreads I can see a new thread created after a couple of...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9984
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.