[PHP] RE: odd class/session/db behaviour

2002-05-29 Thread Tim Ward

I'm not sure if this is your problem but are you closing the connection
anywhere in the script?

e.g.

function Fred()
{   $freddb = mysql_connect(servername,user,password);
mysql_close($freddb);
}

$db = mysqlconnect(servername,user,password);
Fred();

Mysql_query(select ..., $db); // will fall over as the connection has been
terminated



Identical attempts to connect in the same script create multiple pointers to
the same connection. 
The resource identifier is scoped to the function in the case above but the
connection isn't.

This may not have anything to do with your problem but it's something that
tripped me up when
I started doing OOP stuff in PHP.

Tim Ward
www.chessish.com http://www.chessish.com 

--
From:  Nick Wilson [SMTP:[EMAIL PROTECTED]]
Sent:  29 May 2002 09:51
To:  php-general
Subject:  odd class/session/db behaviour

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi all
I've been wrestling with a php problem that has, as far as I'm
aware, no
reason to be happening unless php handling of OOP and Sessions is to
blame. This note looks long, but has been *seriously* condensed!


I have an application set up like this (bear with me it *is* simple
:-)

*   Database (MySQL)
*   Class to handle add, edit, delete, list etc (basic
functionality)
*   Admin program  // use the class and forms etc to allow admin of
db

Now the problem appears to be with the sessions and class: the Admin
program is just a big switch statement that reloads itself eachtime
like
this:

switch($mode) {
case add:
do_some_adding();
break;
}

and etc with all the other things it needs to do.

*** The ERROR *

I'm getting 'Access denied' errors sometimes and the only cure I've
found is this:

if I instantiate the class at the top of the Admin program and it
accesses the db then the next time it needs to access the db it wil
fail
unless I instantiate a new class? 

Very odd. 

The class holds properties of $this-user, $this-host, $this-pass
and
uses them in an private method $this-_db_connect() so I see no
reason
why it should be doing this.

It doesn't appear to be losing the properties, just not being able
to
connect to the db.


* Conclusion ***

Until someone points out the blindingly stupid mistake I'm making
;-)
I'll have to assume their is some OOP/Sessions problem, sure I have
a
solution, but it is very messy, inelegant, and destroys the point of
using a class and session for this purpose.

Can anyone shed any light on this?

Many thanks
- -- 
Nick Wilson //  www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE89JB5HpvrrTa6L5oRArInAKCbmvkGII1uJ5Olmm3oRFyTUhlnDwCeL/xp
Jm00SFzoHn/NNqNuGSCj0Vs=
=d6TN
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: odd class/session/db behaviour

2002-05-29 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* and then Tim Ward declared
 I'm not sure if this is your problem but are you closing the connection
 anywhere in the script?

Nope.  thanks though...
- -- 
Nick Wilson //  www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE89KRUHpvrrTa6L5oRAg6nAKCbmOl+EbwUCsjgai7Oqycqg1rnSQCfeDh/
sG2ojG5hCrzMDUN+gu+1aHk=
=ogY2
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php