473,503 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when to use mysql_close and unset()

Howdy all,

I'm progressing with PHP but I have 2 questions that are kinda bugging
me.

Say for example, I have a php page similar to this....

if .....

if........

elseif......

else........

else ....

etc. where I have if/else statements nested in other ones.

Now I guess it's good practice to unset created variables within each
if or else section as a) it's less work and b) secure (correct me if
I'm wrong).

IF I'm using mysql_close, do I just need to open one connection at the
top of the page and close it at the bottom, as I think I understand
that php will only run queries within if/else which evaluate to true
(and so all can use one connection), and then I can close the
connection at the bottom of the page as php will go through all the
code?

I hope that made sense :o)
Jul 17 '05 #1
5 2832
"ahevans" <ah*****@gmail.com> wrote in message
news:d5*************************@posting.google.co m...
Now I guess it's good practice to unset created variables within each
if or else section as a) it's less work and b) secure (correct me if
I'm wrong).


Never heard of that one, although I can see how some people would do it to
simulate the scoping rule in C++.
Jul 17 '05 #2
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<gK********************@comcast.com>...
"ahevans" <ah*****@gmail.com> wrote in message
news:d5*************************@posting.google.co m...
Now I guess it's good practice to unset created variables within each
if or else section as a) it's less work and b) secure (correct me if
I'm wrong).


Never heard of that one, although I can see how some people would do it to
simulate the scoping rule in C++.


Is it common practice to unset all variables or are they unset when a
browser leaves a page?
Jul 17 '05 #3
ahevans wrote:
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<gK********************@comcast.com>...
"ahevans" <ah*****@gmail.com> wrote in message
news:d5*************************@posting.google. com...
Now I guess it's good practice to unset created variables within each
if or else section as a) it's less work and b) secure (correct me if
I'm wrong).


Never heard of that one, although I can see how some people would do it to
simulate the scoping rule in C++.

Is it common practice to unset all variables or are they unset when a
browser leaves a page?


In PHP, everything ends when the script has completed. So by the time
the page has finished rendering in the user's browser, all variables are
already unset. (Apart from session variables which may have been saved
in a file on the server somewhere.)

JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #4
.oO(ahevans)
Is it common practice to unset all variables
I don't think so.
or are they unset when a
browser leaves a page?


PHP cleans up when the script is finished. The only things I release
manually are resources (DB connections etc.), which can be easily done
in destructors when using OOP.

Micha
Jul 17 '05 #5
> IF I'm using mysql_close, do I just need to open one connection at
the
top of the page and close it at the bottom
Use only one connection. Connect at the top (before your if statements)
and close at the bottom (after all the if statements). You should
always do it this way while you are a beginner to "scope issues".
as I think I understand
that php will only run queries within if/else which evaluate to true
Becareful here.

//example 1
if(true) echo "Hello";
elseif(true) echo " Bob";
else echo " Peterson";

//example 2
if(false) echo "Well! ";
elseif(true) echo "Hello";
elseif(true) echo " Bob";
else echo " Peterson";

Both examples will only print "Hello" not "Hello Bob" or "Hello Bob
Peterson". Any elseif/else statement below another true statement will
not execute.

//example 3
if(false) echo "Hello";
elseif(true)
{
echo "Bob";

if(true) echo " Peterson";
elseif(false) echo " Smith";
else echo " Lesterson";
}

This will print "Bob Peterson".
Now I guess it's good practice to unset created variables within each
if or else section as a) it's less work and b) secure (correct me if
I'm wrong).


Never heard this either, but I am more curious about (a). How is it
less work to unset variables?

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2107
by: lawrence | last post by:
Given a bunch of mixes variables, I'm in a situation where I can't know what type they are. Can I use unset to kill an object? unset($object); Can I use unset to kill a pointer to an open...
21
3354
by: steve | last post by:
Dont’ make my mistake. It is costly. Say you have defined a variable $var in your main script. Now in a function you access it using: global $var; But you want to set it to null inside the...
3
4095
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which...
1
1873
by: frizzle | last post by:
Hi group, Why won't $new_var be unset in the following function? Am i missing out something? Greetings Frizzle. *************************************
7
1836
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which...
7
5223
by: lievendp | last post by:
Just wondering, Is it possible for an instance of a class to unset itself? can I do "unset($this)" or "unset(&$this)" regards, Lieven http://eye.cc php newsgroups
5
2283
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
1
4488
by: Nico | last post by:
Hi all, I've created the following code: <?php session_start(); ?> <FORM METHOD="POST" ACTION="prova.php"> Add <b>Combination</b><br><br>
0
1397
Airslash
by: Airslash | last post by:
Hello, I've written a small function to delete a variable from a class' internal array. The variables on their own are custom class objects, and I'm a bit confused about the whole pass by...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.