Sam Granger Posted June 23, 2007 Share Posted June 23, 2007 I am trying to find whats causing the following warning: Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/php/public_html/mysql.class.php on line 15 I have posted the source below: index.php: <?php include("mysql.class.php"); $DB = new mysql(); $host = "localhost"; $name = "php_sam"; $pass = "123456789"; $db = "php_tips"; $connection = $DB->Connect($host, $name, $pass, $db); //define an SQL statement and execute it $sql = "SELECT id,cat,tip FROM tips"; $query = $DB->Query($sql); //output all rows from the statement while($array = $DB->FetchArray($query)){ extract($array); echo "<b>All rows</b><br /><br />Tip: $tip<b> Cat: $cat<br />"; } //find the number of rows $num = $DB->FetchNum($query); echo "Number of rows: $num"; //close the connection $connection = $DB->Close(); ?> mysql.class.php: <?php class mysql { function Connect($host, $name, $pass, $db){ $connection = mysql_connect("$host", "$name", "$pass"); mysql_select_db("$db", $connection); }//ends the connection function function Close(){ mysql_close($this->connection); }//ends the close function 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; }//ends the query function }//ends the class ?> All help is really appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/56831-not-a-valid-mysql-link-resource-warning-help/ Share on other sites More sharing options...
king arthur Posted June 23, 2007 Share Posted June 23, 2007 In your class.php, you need class mysql { var $connection; function Connect($host, $name, $pass, $db){ $this->connection = mysql_connect("$host", "$name", "$pass"); mysql_select_db("$db", $this->connection); } Quote Link to comment https://forums.phpfreaks.com/topic/56831-not-a-valid-mysql-link-resource-warning-help/#findComment-280817 Share on other sites More sharing options...
Sam Granger Posted June 23, 2007 Author Share Posted June 23, 2007 OMG, you are a life saver!!! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56831-not-a-valid-mysql-link-resource-warning-help/#findComment-280832 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.