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
https://forums.phpfreaks.com/topic/87866-is-unset-the-way/
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
https://forums.phpfreaks.com/topic/87866-is-unset-the-way/#findComment-449519
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.