Jump to content

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!

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);
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.