Jump to content

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


Sam Granger

Recommended Posts

[code]<?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;
  }

}
?>[/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!
Link to comment
Share on other sites

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());}
Link to comment
Share on other sites

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.