kalsarao Posted March 31, 2008 Share Posted March 31, 2008 Hi, I am new to PHP . I hired a freelance Developer, and he left the project and he didn't close MYSQL connections in the Programs. He has class as below <?php class connection{ function GetMyConnection() { $g_link = mysql_connect( 'h.sss.net', 'test_data', 'TEST') or die('Could not connect to server.' ); mysql_select_db('test_data',$g_link) or die('Could not select database.'); return $g_link; } function CloseMyConn() { mysql_close($g_link); } } ?> He is opening Connection as -> $Objconn=new connection(); $conres=$Objconn->GetMyConnection(); Could some on help me , how to close this connection.... Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/ Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 just use mysql_close() at the very end of your script. this should on its own close the current mysql connection Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/#findComment-505696 Share on other sites More sharing options...
kalsarao Posted March 31, 2008 Author Share Posted March 31, 2008 Hi, Thanks for the Reply He created a Function function CloseMyConn() { mysql_close($g_link); } How do i use this? Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/#findComment-505699 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 notice how he called the connection: $Objconn=new connection(); $conres=$Objconn->GetMyConnection(); to close it simply: $Objconn->CloseMyConn(); (Edit: i had the wrong function name lol) hope this helps, Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/#findComment-505731 Share on other sites More sharing options...
trq Posted March 31, 2008 Share Posted March 31, 2008 If the CloseMyConn() you posted within the connection class really is what he coded it will not work and will in fact throw an error as $g_link is not a connection resource. Its out of scope. Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/#findComment-505732 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 you could also: mysql_close($conres); to specifically close the connection handle made from the initial connection. but you dont need to, to just close mysql connections its much easier/efficient and practical to just use mysql_close(); ---------- thorpe is correct, this function: function CloseMyConn() { mysql_close($g_link); } would fail (Invalid mysql result resource). use this instead: function CloseMyConn($g_link) { mysql_close($g_link); } then $Objconn->CloseMyConn($conres); to close Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/#findComment-505735 Share on other sites More sharing options...
kalsarao Posted March 31, 2008 Author Share Posted March 31, 2008 This works, Great Guys, Thanks Very much :-) Link to comment https://forums.phpfreaks.com/topic/98829-mysql-connection-close/#findComment-505781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.