Basic php & MySql Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Basic php & MySql Question

Post by steves »

Too bad there's not a newbie forum ...

I have 2 very basic questions:

1) When I use mysql_connect in a page, how long does that connection stay alive? If the page redirects to another page, will the connection still be available until the connection is actively closed? How do I close it? (The php manual says that "Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. "

2) Similarly, how long do variables persist? If I define $employee on a login page, when will $employee lose its value?

Thanks.
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

basicly when the script finishes all variables (exept session variables) destroyed and database connections and file handles are closed.
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

okay, really dumb question, then:

by definition, when does the script end? it can't be at the ?> tag, because i've got pages where there are multiple

Code: Select all

<?php

     CODE GOES HERE

?>

     SOME HTML

<?php

     MORE CODE GOES HERE

?>
and the variables are (seem to be, anyway) available throughout.

so, for the guy who's not a programmer but trying to teach himself some stuff to get a project done, what's the actual definition of a script?
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

what acctually hapens is that when browser asks server for say mycoolpage.php, servers sees that it is a *.php page so it invokes php parser. this parser is actually a program that takes your php file reads it, interprets your commands and executes it. when parser finished doing all that it takes all the output generated by your page and passes it to server. and server passes it to browser.

script is what you have between <?php ... ?> tags
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

hmmm. know where i can read up on this a little? because, like i said above, the variables seem to stay "alive" throughout "mycoolpage.php", even though there are several times when i close scripts. in other words, when i have more than one script on a page, the variables don't stop workin'.

just trying to figure it out. thanks for your help.
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

aa ok i see now what you are asking...

yes despite that you close <?php ?> blocks variables are still there...
the point is that variables destroyed when php parser finishes parsing.
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

great! when does the php parser stop parsing? at </html> ? nope, couldn't be - several of my pages have no HTML tags at all. and is it the same thing for MySql connections and queries?

very confused.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it stops parsing at the end of the file.
Post Reply