Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Whether msyql connection will last untill we go to next page?
Old 02-25-2009, 09:00 AM Whether msyql connection will last untill we go to next page?
Junior Talker

Posts: 2
Name: Rex Sunny
Trades: 0
I want to know that if we are connecting mysql using mysql_connect , the connection to the db will last untill we go to the next page? or after every transaction the mysql detach the connections....
Can some one please explain about mysql connection scope in detaill....????
rexpsunny is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-25-2009, 09:48 AM Re: Whether msyql connection will last untill we go to next page?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
http://www.php.net/manual/en/function.mysql-connect.php
Quote:
Note: The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-26-2009, 07:51 PM Re: Whether msyql connection will last untill we go to next page?
randon's Avatar
Experienced Talker

Posts: 46
Name: Brandon
Trades: 0
If you are using only 1 database for your website just add a connection to the header of your page, that way you are only connecting once, and if you need to change connection info for any reason, you only need to edit one spot.
__________________

Please login or register to view this content. Registration is FREE
Web development blog and scripts.
randon is offline
Reply With Quote
View Public Profile
 
Old 02-26-2009, 08:44 PM Re: Whether msyql connection will last untill we go to next page?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by randon View Post
If you are using only 1 database for your website just add a connection to the header of your page, that way you are only connecting once, and if you need to change connection info for any reason, you only need to edit one spot.
Even if you include your database code in your header you will still have to connect everytime the header is called (ie for each new page).

You are, however, right about localizing your database code. I usually have a db.php file containing my database code, and I just include if I need to access the database. This will not prevent your database connection from closing when your script is finished executing (as Tripy said).
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-26-2009, 10:37 PM Re: Whether msyql connection will last untill we go to next page?
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
The short explanation is this...

when you create a connection, it is not closed until one of two things happens.

1) you call mysql_close()

2) the page execution ends.

If you don't call mysql_close(), the connection will stay open until you're page finishes execution.
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to Whether msyql connection will last untill we go to next page?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21583 seconds with 12 queries