Jump to content

Is unset() the way?


Aureole

Recommended Posts

Say I have 3 queries on a page, I'll do things like...

 

<?php
$queryA = "";
$resultA = mysql_query( $queryA );

$queryB = "";
$resultB = mysql_query( $queryB );

$queryC = "";
$resultC = mysql_query( $queryC );
?>

 

Now I used to just use $query, $result etc. for all my queries but that caused problems with queries sometimes, but it gets annoying having to number/letter things.

 

As far as I'm aware, if I do something like this:

 

<?php
$var = "123";
$var = "abc";
echo( $var );
?>

 

The output will be "abc" as the second will overwrite the first, but when querying this doesn't seem to be the case sometimes... I had some really annoying problems and it took me ages to realize that it's because I kept using $query etc. over and over.

 

Like I said, it's growing tiresome naming/numbering each query so if I started doing something like this:

 

<?php
$query = "";
$result = mysql_query( $query );
unset( $query); unset( $result );

$query = "";
$result = mysql_query( $query );
unset( $query); unset( $result );

$query = "";
$result = mysql_query( $query );
unset( $query); unset( $result );
?>

 

Would that stop the problems I was experiencing?

Link to comment
Share on other sites

Nope. That closes the connection completely, tested it as well:

 

<?php

$c = mysql_connect('localhost','root') or die(mysql_error());
$d = mysql_select_db('users',$c);

$sql = "SELECT * FROM `users` WHERE `username`='marcus'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);

echo $row['aim'] . "<br>\n";

mysql_close();

$sql = "SELECT * FROM `users` WHERE `username`='lemonade'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);

echo $row['aim'] . "<br>\n";

?>

 

results:

 

lifeg0eson666

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\webserver\www\test\mysql close.php on line 15

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\webserver\www\test\mysql close.php on line 15
Access denied for user 'ODBC'@'localhost' (using password: NO)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.