Hi all, I always see that every large code has not a closed connection, is it mean when I have a small code I will close and when I have a large code I will not close the connection ? here is one of my codes, so how to close, because my connection is in a file called connection.php . <?php include("../connection.php"); $DeptID =htmlentities(mysql_real_escape_string($_POST[Dept_ID])); $query = "SELECT * from departement where deptID= '$OpID' " ; $result = mysql_query($query) ; ?> <table width="655" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><strong>Dept ID </strong></td> <td><strong>Dept Name </strong></td> <td><strong>Location </strong></td> </tr> <?php while($rows= mysql_fetch_array($result)) { ?> <tr> <td> <?php echo $rows[0] ;?> </td> <td> <?php echo $rows[1] ;?> </td> <td> <?php echo $rows[2] ;?> </td> </tr> <?php } ?> </table> Code (markup): I ask this Question because I sometimes see in my web page Error of connection " To many connection ". I dont know the cause ? so plz help me , thank u 4 ur Time.
Anytime My Friend... Yes... If U'll Not Close Your Connection... Some One Genius Can Hack Your CODE Easily So Close Your Connection When U Feel That Your PHP Work Has Been DONE On The Page.
As far as i know, mysql automatically closes connection on the end of your script although you do not put "mysql_close()" on your script, except your script use persistent connection (mysql_pconnect) Assuming your script does not use persistent connection, it means your server (actually the mysql) is not powerful enough to handle too many visitors.