note 89744 added to function.mysql-close

From: Date: Fri, 20 Mar 2009 23:18:11 +0000
Subject: note 89744 added to function.mysql-close
Groups: php.notes 
Request: Send a blank email to php-notes+get-152242@lists.php.net to get a copy of this message
I disagree with Jonbarnett that mysql_close is unuseful. I have been on a tight budget recently. I have been using a free web host and so mysql_close is very important. It always gives an error: mysql_max_connections because I don't close my connection until the end. Although you said that it would slow down transferring to the client, it will still allow your script to run. If I use mysql_close, my down time will be reduced by over 20%. Currently my website has a 80% dowtime and I hope to change that to 95% with the newer mysqli functions and mysqli_close. Also, If you are trying to make scripts to work on PHP4, be prepared for the future. You should just start at 5 or even 6 if your web host supports it which I doubt unless you are running on a dedicated server. Php has a new extension called mysqli functions which is better than the mysql functions. So Tip: If you are struggling with a lot of down time with mysql connections, you should probably switch hosts or use mysql close. You should try an follow this structure: <?php //Do some validation $article_name = stripslashes($_GET['article']0); //Database variables define(db_host,'localhost'); define(db_username,'username'); define(db_password,'password'); //Connect to the database $link = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); //Try to minimize time you are in the mysql connection. Although this is slower, the time in mysql less. (Especially useful if your host restricts max connections) //Only do things that you need to do within a mysql connection. $article_name = mysql_escape_string($article_name); //Get some random results $result = mysql_query("SELECT * FROM sometable WHERE id='$article_name;"); //Close the connection before doing anything else if you are not going to run any more queries mysql_close($link); //Start to do things after you close the link $row = mysql_fetch_row($result); echo $row[0]; ?> ---- Server IP: 64.71.164.2 Probable Submitter: 206.188.48.57 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-close.php Edit -- https://master.php.net/note/edit/89744 Del: integrated -- https://master.php.net/note/delete/89744/integrated Del: useless -- https://master.php.net/note/delete/89744/useless Del: bad code -- https://master.php.net/note/delete/89744/bad+code Del: spam -- https://master.php.net/note/delete/89744/spam Del: non-english -- https://master.php.net/note/delete/89744/non-english Del: in docs -- https://master.php.net/note/delete/89744/in+docs Del: other reasons-- https://master.php.net/note/delete/89744 Reject -- https://master.php.net/note/reject/89744 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152242) next »