PHP - Mysql_close
Hi got a quick question about mysql_close.
I'm currently learning PHP from someone with an ASP background. And we were processing a form to another page. (both these pages had a connection to a database.) We wanted to bring the external page into the original form page so we just copy and pasted the code in and it wasn't working. We commented everything out and it turned out it didn't like two mysql_close in the same page. Why is that if the first connection is already closed? I know it's better to use include files for connecting to the database but we are going slowly and learning one step at a time. Similar TutorialsHello members. I am wondering if "mysql_close($connection);" needs to be put at the end of every .php page that connects to my MySQL database or if I can just place it at the end of the logout script since that will be the last page any user accesses. Is it important to close the connection between PHP and MySQL after each page has been generated? I ask because I have been getting very embarrassed in front of my boss because on work computers the pages I code have multiple timeouts when connecting to the DB. I am hoping that there is a way to connect to the DB and leave the connection open for a while so the user experiences less timeouts. I've messed with the timeout variable in php.ini, but its default was 3 seconds and I kept it at 5. The timeout returns an error plenty before 3 seconds. My DB host is a reliable remote DB; servage.net, so it can't be their problem. I'm a newbie and notice that all my .php pages (files, scripts--what are they called?) begin with Code: [Select] <?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. |