View Single Post
Old 07-01-2007, 5:09 PM   #3
KAH
 
KAH's Avatar
 
Posts: n/a
My Photos: ()

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Global variables help...

"Andy Hall" <andy@jaar.co.uk> wrote in
news:bhibv2$16j$1@sparta.btinternet.com:

> Long Version:
> I have a mysql connection set up, "$db_link" which I have declared as
> global in the following way:
>
> global $db_link;
> $db_link = mysql_connect(...);


See the other reply on that.

> However, the script is erroring saying it cannot find $db_link. So I
> tried passing the variable from the calling statement to the function:
>
> closeDB($db_link)
> function closeDB($db_link)
> {
> mysql_close($db_link);
> unset($db_link);
> }


You're not passing the real link resource. In this case, you should be
passing it by reference (similar to pointers in C). You can do it in two
ways AFAIK:

closeDB (&$db_link);

OR

function closeDB (&$db_link) {

KAH
  Reply With Quote