Yes, It is necessary because script executes & ends for every request. Variables can be made persistent by using cookie/sessions but mysql connection is a resource which can not be saved & restored as session variable.
For efficient use of resources, you may use mysql_pconnect() (only when php is used as module), but still you have to use it in every script. The only difference is that mysql_pconnect() will *use any previously open mysql connection & use it instead of making fresh connection to mysql *if a fresh connection is made, it will not be closed when script ends. regds, -----Original Message----- From: Iggy [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 19:20 To: [EMAIL PROTECTED] Subject: connecting to mysql db hi, I am trying to play and learn php along with mysql and I have a question about connecting to a db. Is the following code necessary on every php page where I am retrieving some data from a db or is there any way to connect once (something like index.php) and have that connection open through subsequent pages? the code <?php $link = mysql_connect("localhost", "", "") or die("Could not connect: " . mysql_error()); print ("Connected successfully"); mysql_select_db("test") or die("Could not select database: " . mysql_error()); ?> thanx iggy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php