Jump to content

Not a valid MySQL-Link resource warning... Help!


Sam Granger

Recommended Posts

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!

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.