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


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

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

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

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
        *   Admin program  // use the class and forms etc to allow admin of

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

        switch($mode) {
            case "add":

        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
        unless I instantiate a new class? 

        Very odd. 

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

        It doesn't appear to be losing the properties, just not being able
        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
        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)

        -----END PGP SIGNATURE-----

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

Reply via email to