NYCPHP Meetup

NYPHP.org

[nycphp-talk] mysql_close() error

Frank Wong frank_wong2 at informationideas.com
Tue Dec 21 17:26:55 EST 2004


Aha, thanks for the input.  I found the problem. But I need a bit of
education as to why this works this way.

Once I narrowed it down, I found that there was another function I was
calling which mysql_close($link). So what I don't understand is the scope of
$link.

If I have

function one() {
	$link = mysql_connect(...
	mysql_close($link);
}

function two() {
	$link = mysql_connnect(...
	one();
	$mysql_close($link);
}

the var $link from function two is automatically referenced by function one
even though I did not pass it in?

Sorry if this is a newbie question.  Thanks.


Frank

-----Original Message-----
From: talk-bounces at lists.nyphp.org
[mailto:talk-bounces at lists.nyphp.org]On Behalf Of Daniel Convissor
Sent: Tuesday, December 21, 2004 5:16 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] mysql_close() error


On Tue, Dec 21, 2004 at 04:20:31PM -0500, Frank Wong wrote:
>
> Warning: mysql_close(): 12 is not a valid MySQL-Link resource

Sounds like the database connection was already closed somewhere else
in your scripts.  Comment out all calls to mysql_close() except this
one you're talking about.

If that isn't it, how about doing some debugging?  What you've given
here is pseudo code, leaving out a lot of stuff, so ther's no way we
can know what's really going on, plus having such a large example is
distracting you from the problem at hand.  You need to make a REAL
self contained example that breaks down everything to the simplest
level possible:

<?php
 // set the $host, etc, vars here...

 $link = mysql_connect($host, $sys_user, $sys_password)
         or die("Could not connect : " . mysql_error());
 mysql_select_db($sys_db)
         or die("Could not select database");
 mysql_close($link);
?>

--Dan

--
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409
_______________________________________________
New York PHP Talk
Supporting AMP Technology (Apache/MySQL/PHP)
http://lists.nyphp.org/mailman/listinfo/talk
http://www.newyorkphp.org





More information about the talk mailing list