Hey all,

Have a very peculiar problem. First off -

OS: FreeBSD 4.7
MySQL version: Ver 12.20 Distrib 4.0.13, for unknown-freebsd4.7 (i386)
(I have also compiled 3.23.53)

The problem:
I have written a class that connects to and disconnects from the database.
Everything works fine when I instantiate this class in another class to do
some work, but when that class instantiates yet another class then it seems
as though mysql_real_connect bombs, and I have a core file.

In other works
Works:
class1 {
        function foo() {
                MYSQL mysql
                db.connect (&mysql)
        }
};

Does not work:

Class1 {
        function foo() {

                Class2 cl2;
                        cl2.fod()
        }
}

Class2 {
        function fod() {
                db.connect()
        }
}

I have done all sorts of debugging and inspection, but I am unable to figure
out what is causing this. Please send any ideas.

DB function is here.
(mysql_ptr points to a valid MYSQL object elsewhere)

MYSQL *DB::db_connect (MYSQL* mysql_ptr) {
        /*
         * connect to the database
         */
        char msg_buffer[2000];
        Log log;


        /*
         * initialize the MYSQL pointer
         */
        mysql_ptr = mysql_init(mysql_ptr);
        if (mysql_ptr == NULL) {
                printf ("ERROR: ptr is null!\n");
        }

        if (!(mysql_real_connect (mysql_ptr, borg.db_host,
borg.db_username,\
                         borg.db_passwd, borg.db_name, atoi(borg.db_port), NULL, 0))) {
                memset (msg_buffer, 0, sizeof(msg_buffer));
                sprintf (msg_buffer, "ERROR: Failed to connect to database:
Error: %s.", mysql_error(mysql_ptr));
                log.log_entry (0, msg_buffer);
                return NULL;
        }


        return mysql_ptr;
};


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to