PHP-MY SQL question

anuj_web

New Member
Messages
145
Reaction score
0
Points
0
Hi,

I want to ask that when we switch between two or more php pages do we have to again re-establish connection with database

And one more... that dont we have to close the database after opening it ??
 

cowctcat

New Member
Messages
401
Reaction score
0
Points
0
if you do something like click a link then yes you do need to reconnect but if you include a page after the connection is formed you dont need to reconnect to use the connection in the included page. This is because all connections are closed at the end of the script unless you manually close them earlier. so no you don't have to close them.
 

anuj_web

New Member
Messages
145
Reaction score
0
Points
0
and one more thing ...is the session vaiable global ..??

where all can i access it...does it have the same reason as above i.e. including files ...
and

do we include files only to share variables ??
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
After one script has called session_start(), the $_SESSION variable is available anywhere after this, in included files as well.

As for why to include files, it's usually to either break up a large script or share common code between multiple scripts. A good example of this is that many sites will have a common.php file or something of the like which performs any required preliminary tasks such as defining variables/constants, including more files, connecting to the db, and anything else relevant to the site.
 

anuj_web

New Member
Messages
145
Reaction score
0
Points
0
hI

THANKS WOIWKY 4 replying
i have one more q
How to pass same variables between two or more files ,without making thmem global
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
if you're including the file, then the variable created in the first file will be available in the second file. for example if you have a header file which is included in a main page file, and have a variable created in main page $page_name, then in header, so long as it was created before header was included, you can access $page_name and modify it if you so choose.
 
Top