Jump to content


Photo

Help, small error. MySQL Class. Not sure if I fixed it correctly?


  • Please log in to reply
4 replies to this topic

#1 Sam Granger

Sam Granger
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 11 October 2006 - 10:31 AM

<?php
include ('./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;
  }

}
?>

I have this file included in another php file. When I do this:

$DB->Close();

I get the following error:

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/sgclient/public_html/mysql_class.php on line 16


I tried changing:

  function Close(){

    mysql_close($this->connection);

  }

to:


  function Close(){

    mysql_close();

  }
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!

#2 mjlogan

mjlogan
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 11 October 2006 - 10:36 AM

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

#3 Sam Granger

Sam Granger
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 11 October 2006 - 10:40 AM

$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.

#4 Sam Granger

Sam Granger
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 11 October 2006 - 10:54 AM

I still get the same error. :(

#5 mjlogan

mjlogan
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 11 October 2006 - 04:24 PM

Sorry, I wasnt very clear.

Have you actually opened a mysql connection on that page?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users