In one case I do need to jump back and forth between databases that are on different physical servers. What's the most efficient way to handle this?

On Aug 2, 2005, at 11:14 AM, Devananda wrote:

Brian Dunning wrote:

My RaQ4 is throwing the "Too many connections" error. Now, it is getting hit pretty hard by traffic, but I wonder if my coding might be exacerbating this error. Due to my relatively lazy structure of includes and functions, my pages might have half a dozen or so of these (most are to the same database):
$connection = mysql_connect($db_host, $db_username, $db_password);
mysql_select_db($db_name, $connection);
Is that creating half a dozen connections, even though it's just one web user?


Yep. Each call to mysql_connect creates a new connection to the database. If you need to connect to multiple database servers then you obviously need multiple connections, but if you are only connecting to one database server, then you should really reuse a single connection. FYI, the process of creating a new connection requires substantially more processing time than executing a simple query (ie, mysql_select_db).

One common practice is to have a single include file which creates the database connection and instantiates a global variable with the handle to that connection. Then, all pages which include that file merely use that handle to communicate with the database.

Regards,
Devananda vdv



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to