After connecting to MySQL...
Moderator: General Moderators
After connecting to MySQL...
Are you continuously connected?
When does your session end? If I were trying to create a forum like PHPBB, would I have to connect to the database on each page of the script?
When does your session end? If I were trying to create a forum like PHPBB, would I have to connect to the database on each page of the script?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
So if I leave this forum and go to the http://www.devnetwork.net, I'm still connected to whichever database you guys use for this forum?
And if I create a file that connects a user to a database, his connection doesn't ever expire?
Or does it end at certain times (like mysql_close() or perhaps after closing a browser window)?
I'm sorry I'm thickheaded... just trying to get it all together.
And if I create a file that connects a user to a database, his connection doesn't ever expire?
Or does it end at certain times (like mysql_close() or perhaps after closing a browser window)?
I'm sorry I'm thickheaded... just trying to get it all together.
-
samscripts
- Forum Commoner
- Posts: 57
- Joined: Tue Apr 23, 2002 4:34 pm
- Location: London, UK
Unless you call mysql_close() or some kind of major error occurs, the connection will last from when you open it until the end of that script.Are you continuously connected?
Once the script finishes the connection is gone, so you will need to connect to the database for every script that needs to get some data.
Your user will only be connected to the db while that script executes on that occasion. (ie. the db connection will not persist over different scripts)
Sam
- sam
- Forum Contributor
- Posts: 217
- Joined: Thu Apr 18, 2002 11:11 pm
- Location: Northern California
- Contact:
A connection runs as long as the php page is being parsed, as soon as the html is sent to the browser from the server the connection is lost.Jim wrote:So if I leave this forum and go to the http://www.devnetwork.net, I'm still connected to whichever database you guys use for this forum?
And if I create a file that connects a user to a database, his connection doesn't ever expire?
Or does it end at certain times (like mysql_close() or perhaps after closing a browser window)?
I'm sorry I'm thickheaded... just trying to get it all together.
Cheers moe
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Ending the connection to the database...
Once the script has finished running, i.e. once the page has been fully loaded, the database connection is ended so no. The script doesn't continuously run therefore the connection is not eternal.Jim wrote:So if I leave this forum and go to the http://www.devnetwork.net, I'm still connected to whichever database you guys use for this forum?
If you create a file that connects a user to a database the connection will last for as long as the code in the file (the script) is being run. If the user then goes to another page that requires a database connection a new one will be started and ended in the same way.Jim wrote:And if I create a file that connects a user to a database, his connection doesn't ever expire?
Or does it end at certain times (like mysql_close() or perhaps after closing a browser window)?
If you want to be sure that connections are being ended you should use the mysql_close() function once you've finished querying the database but it's not strictly necessary.
http://www.php.net/manual/en/function.mysql-connect.php
http://www.php.net/manual/en/function.mysql-close.php
Hope this helps
Mac
Thanks amigo.
So, in the case that I have several pages that would require a connection to the database to work properly (as I assume these forums do) would I have to put the connection code on every page?
It doesn't seem that every .php page in the phpBB files have a MySQL connection code at the top...
Please explain how this works. I'm 'tarded
Thanks guys!
So, in the case that I have several pages that would require a connection to the database to work properly (as I assume these forums do) would I have to put the connection code on every page?
It doesn't seem that every .php page in the phpBB files have a MySQL connection code at the top...
Please explain how this works. I'm 'tarded
Thanks guys!
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Create a file with the connection code in it and include that at the top of all the pages that need a database connection. That way if you change the database name, or the username or password used to access it you only have to adjust one file.Jim wrote: would I have to put the connection code on every page?
It doesn't seem that every .php page in the phpBB files have a MySQL connection code at the top...
Nice and easy
Mac
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact: