0

PSA: do not use mysql_ functions. See an explanation below in the answers.

I have a mysql.php file with a class named dbAccess which handles my insert queries. I didn't have any issues with this file until today, and I'm not sure if I accidentally changed something or what.

The warning is:

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/www/data/dbAccess/mysql.php on line 83

line 83 is this:

mysql_close($this->dbserver);

dbserver defined as private $dbserver;. the server is set with

$this->dbserver = "my.server.address.com"

Don't really know what I'm doing wrong with this one... Like I said it was working fine until today so I must of accidentally hit something in one of my other files which use the class? pointers on where to look are much appreciated.

tdc
  • 5,174
  • 12
  • 53
  • 102
  • Please. [Do not use `mysql_` functions in PHP](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – Nic Wortel Dec 13 '13 at 01:55
  • 1
    The string "my.server.address.com" is not a valid MySQL-Link resource, is it? – Pekka Dec 13 '13 at 01:55
  • There are many many results when Googling `"Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource"` Pick one. Probably an "out of scope" issue. – Funk Forty Niner Dec 13 '13 at 02:01
  • 1
    Enough lecturing on `mysqli_` versus `mysql_`. It’s non-constructive & not helpful to the issue at hand. – Giacomo1968 Dec 13 '13 at 02:05
  • @JakeGould I don't agree with you here. Other people might see this question and not know about `mysql_` being deprecated. I see you have edited my answer, but I've added a (smaller) warning at the bottom of my answer. – Nic Wortel Dec 13 '13 at 02:08
  • 1
    @Nic The main reason you are upset is that I edited your question which lambasted the original poster at every turn. Either answer the question & simply assert your `mysqli_` info, or just don’t add it. But you are not the first person to lecture others on `mysqli_` here. And it is counter-productive. – Giacomo1968 Dec 13 '13 at 02:21
  • @JakeGould I'm not upset about it and I certainly wasn't trying to lecture people - and I apologize if I made that impression. I was simply trying to warn whoever would read that answer, because there are still far too many people who don't seem to know that using `mysql_` functions isn't a very good idea anymore. That's all ;) – Nic Wortel Dec 13 '13 at 02:25
  • Take it outside boys. Anyone is entitled to signal the deprecation of the `mysql_` function; let's just leave it at that, shall we? – Funk Forty Niner Dec 13 '13 at 02:26
  • No worries gentlemen :) I appreciated both your input. Thanks for the help! Now to figure out this bloody `Unable to jump to row 0 on MySQL result index..` issue... :| – tdc Dec 13 '13 at 02:31

1 Answers1

4

mysql_close() accepts a connection resource as parameter - you're passing a string (my.server.address.com).

The resource is returned by mysql_connect(). You probably have something like this in your code:

$connection = mysql_connect(...);

Simply use pass this variable to mysql_close():

mysql_close($connection);

If you didn't store the connection in a variable, you can call mysql_close() without parameters as well.

"If link_identifier isn't specified, the last opened link is used."

It's not even necessary to use mysql_close(), because open connections are closed automatically at the end of the script's execution.

See http://www.php.net/mysql_close for more information.

Attention: For other people that are reading this answer: please note that mysql_ functions are deprecated.

Nic Wortel
  • 11,155
  • 6
  • 60
  • 79
  • For whatever reason, the connection was never associated with a variable. It's just `mysql_connect($this->dbserver,$this->username,$this->password); mysql_select_db($this->dbname);` – tdc Dec 13 '13 at 02:07
  • 1
    And yes for the record -- listen to everyone here fellow coders, never use mysql_. I've learned my lesson :) – tdc Dec 13 '13 at 02:09
  • Well that's not a problem either. It's an optional argument, you can call `mysql_close()` without any parameters as well. You can even omit `mysql_close()` completely - see http://www.php.net/mysql_close – Nic Wortel Dec 13 '13 at 02:10