Page 1 of 1

Basic php & MySql Question

Posted: Fri Feb 24, 2006 4:36 pm
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.

Posted: Fri Feb 24, 2006 4:39 pm
by newmember
basicly when the script finishes all variables (exept session variables) destroyed and database connections and file handles are closed.

Posted: Fri Feb 24, 2006 4:54 pm
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?

Posted: Fri Feb 24, 2006 5:00 pm
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

Posted: Fri Feb 24, 2006 5:15 pm
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.

Posted: Fri Feb 24, 2006 5:31 pm
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.

Posted: Fri Feb 24, 2006 6:04 pm
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.

Posted: Fri Feb 24, 2006 6:27 pm
by feyd
it stops parsing at the end of the file.