Aureole Posted January 26, 2008 Share Posted January 26, 2008 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 More sharing options...
darkfreaks Posted January 26, 2008 Share Posted January 26, 2008 jusr do mysql_close after eac query Link to comment https://forums.phpfreaks.com/topic/87866-is-unset-the-way/#findComment-449506 Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 You tell me <?php $var = "pie"; echo "Set: " . $var . "<br>\n";; unset($var); echo "Unset: " .$var; ?> Set: pie Unset: Link to comment https://forums.phpfreaks.com/topic/87866-is-unset-the-way/#findComment-449507 Share on other sites More sharing options...
Aureole Posted January 26, 2008 Author Share Posted January 26, 2008 Will mysql_close() do the trick? Link to comment https://forums.phpfreaks.com/topic/87866-is-unset-the-way/#findComment-449513 Share on other sites More sharing options...
hitman6003 Posted January 26, 2008 Share Posted January 26, 2008 mysql_close will disconnect you from the db which if you have more queries to execute isn't desirable...use mysql_free_result which will remove that query result from memory.... http://www.php.net/mysql_free_result Link to comment https://forums.phpfreaks.com/topic/87866-is-unset-the-way/#findComment-449518 Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.