Jump to content

should one mysql_close db at end of every .php page that opens it?


cflores59

Recommended Posts

I'm a newbie and notice that all my .php pages (files, scripts--what are they called?) begin with

<?php

/* Change next two lines if using online*/
$db="..........";
$link = mysql_connect('localhost', ....................');
if (! $link) die(mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error());

and end with 
mysql_close($link);
      ?>

 

Is this standard or should I leave it open til I'm finished and then close?????????????????? Altho I experimented with not closing & opening & it seemed that by doing so I couldn't access the next table I was after.

You typically don't need to explicitly close the connection at all. php takes care of that at the termination of the script.

 

Using mysql_close isn't usually necessary' date=' as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.[/quote']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.