Sam Granger Posted October 11, 2006 Share Posted October 11, 2006 [code]<?phpinclude ('./includes/db_settings.php');class mysql { function Connect($DB_SERVER, $DB_USER, $DB_PWD, $DB_NAME){ $connection = mysql_connect("$DB_SERVER", "$DB_USER", "$DB_PWD"); mysql_select_db("$DB_NAME", $connection); } function Close(){ mysql_close($this->connection); } function FetchRow($query){ $rows = mysql_fetch_row($query); return $rows; } function FetchArray($query){ $array = mysql_fetch_array($query); return $array; } function FetchNum($query){ $num = mysql_num_rows($query); return $num; } function Query($sql){ $query = mysql_query($sql) or die(mysql_error()); return $query; }}?>[/code]I have this file included in another php file. When I do this:[code]$DB->Close();[/code]I get the following error:[quote]Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/sgclient/public_html/mysql_class.php on line 16[/quote]I tried changing:[code] function Close(){ mysql_close($this->connection); }[/code]to:[code] function Close(){ mysql_close(); }[/code]And the error disappears. However I'm not the best at php. This mysql function was not written by me. Is this the correct fix? Or should it be something else?Thanks in advance for any help and thanks for reading! Quote Link to comment Share on other sites More sharing options...
mjlogan Posted October 11, 2006 Share Posted October 11, 2006 Have you checked that you have actually opened the mysql connection, because you could be trying to close a connection that does not exist.And try or die(mysql_error()); after it to see if it throws an actually error. function Close(){ mysql_close($this->connection) or die(mysql_error());} Quote Link to comment Share on other sites More sharing options...
Sam Granger Posted October 11, 2006 Author Share Posted October 11, 2006 $connection = $DB->Connect($DB_SERVER, $DB_USER, $DB_PWD, $DB_NAME);This code should open the connection, correct? If this is the case I have opened it. Let me try what you just suggested. Quote Link to comment Share on other sites More sharing options...
Sam Granger Posted October 11, 2006 Author Share Posted October 11, 2006 I still get the same error. :( Quote Link to comment Share on other sites More sharing options...
mjlogan Posted October 11, 2006 Share Posted October 11, 2006 Sorry, I wasnt very clear. Have you actually opened a mysql connection on that page? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.