1 (edited by AlanCollier 2007-10-28 23:17)

Topic: Error: Unable to fetch group info.

Hi

I'm creating pages that dip in and out of punBB and my own scripts, the subsequent punbb related scripts are failing thus..

PunBB reported: Unable to fetch group info

Database reported: Table '****.punbb_groups' doesn't exist (Errno: 1146)

(Where **** is the other database I've been querying.)

Is it that I've managed to change the $db->prefix variable?!
or is it that the punbb mysql db code doesn't explicitly state it with each query and thus mysql is just using the last one used?
Is there a workaround?

All help appreciated.

--Alan

Re: Error: Unable to fetch group info.

PunBB does explicitly specify which connection to use. However, if YOU executed a command to switch databases without specifying the link, PHP defaults to using the most recently opened link.

Re: Error: Unable to fetch group info.

Ok, that makes sense.

Here's the code I use to connect to the other database:

                $connection = mysql_connect ($hostname, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($databasename);

                if (!($result2 = @ mysql_query($strsql2, $connection))) die("Error " . mysql_errno(  ) . " : " . mysql_error(  ));

Am I stepping on punbb's toes with the $connection name?
Otherwise, how can I switch PHP/MySQL back to the right connection?

Thanks for the super-quick reply BTW!!

--Alan

Re: Error: Unable to fetch group info.

mysql_select_db can take a connection as an argument (and needs to).

Re: Error: Unable to fetch group info.

The easiest way is to create a second DB object smile

Re: Error: Unable to fetch group info.

How do I that?
(sorry I'm going to be a n00b for the 1st ten years!)

Re: Error: Unable to fetch group info.

$db2 = new DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect);

Then just modify in there what you need.

Re: Error: Unable to fetch group info.

I get the rest, but what is:  $p_connect ??

Thanks

Alan

Re: Error: Unable to fetch group info.

It determines whether or not to setup a persistent connection to the database. Generally, you don't want this so just set it to false.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Error: Unable to fetch group info.

Thanks.

Re: Error: Unable to fetch group info.

Hmm

This doesn't seem to have solved my problem.

I'm essentially calling several scripts to build my page, some of my own and some punbb related (extern.php).
When extern.php is called, it returns this error:

PunBB reported: Unable to fetch group info

Database reported: Table 'anotherdb.punbb_groups' doesn't exist (Errno: 1146)

Which I know means it (MySQL) is looking at the wrong database (anotherdb).

This is despite me setting up a second db object, called $db2 and using that to access my database in my own scripts. I don't have any mysql_select_db commands in my scripts!

All help/ideas appreciated.

Re: Error: Unable to fetch group info.

Am I going to have to modify the mysql code in punbb so that the database is switched before every query?
Seems like an inelegant solution but if someone could help me with that I'd appreciate it.


Alan

Re: Error: Unable to fetch group info.

Can you post your code?

Re: Error: Unable to fetch group info.

I'm assuming that somewhere in here (include\mysql.php):

    function query($sql, $unbuffered = false)
    {
        if (defined('PUN_SHOW_QUERIES'))
            $q_start = get_microtime();

        if ($unbuffered)
            $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
        else
            $this->query_result = @mysql_query($sql, $this->link_id);

        if ($this->query_result)
        {
            if (defined('PUN_SHOW_QUERIES'))
                $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));

            ++$this->num_queries;

            return $this->query_result;
        }
        else
        {
            if (defined('PUN_SHOW_QUERIES'))
                $this->saved_queries[] = array($sql, 0);

            return false;
        }
    }

I'll need to put:

mysql_select_db($db_name, $db)

Re: Error: Unable to fetch group info.

No, the code where you're using the second DB object.

16 (edited by AlanCollier 2007-12-23 00:33)

Re: Error: Unable to fetch group info.

$db2 = new DBLayer($dbx_host, $dbx_username, $dbx_password, $dbx_name, $dbx_prefix, $px_connect);

I then call it with:

                    $result = $db2->query($strsql) or error('Unable to fetch topic list', __FILE__, __LINE__, $db2->error());

                    // If there are records returned
                    if ($db2->num_rows($result))
                        {
                            while ($row = $db2->fetch_assoc($result))
                            {
                            }
                        }

Which all works fine. The problem comes when the page then calls extern.php which gives:

PunBB reported: Unable to fetch group info

Database reported: Table 'anotherdb.punbb_groups' doesn't exist (Errno: 1146)

Re: Error: Unable to fetch group info.

*anotherdb being my database that I'd connected to using $db2

Re: Error: Unable to fetch group info.

So, after you've included extern.php you get the error?

19 (edited by AlanCollier 2007-12-23 15:38)

Re: Error: Unable to fetch group info.

I get the error when I try to include extern.php

I include the PHP stuff first:

// Include PunBB stuff
    define('PUN_ROOT', 'messageboard/');
    require PUN_ROOT.'include/common.php';
    define('PUN_TURN_OFF_MAINT', 1);
    define('PUN_QUIET_VISIT', 1);

Then include my scripts, which use $db2. Then I include extern.php

Essentially I think that the current database is being switched to my db (as defined by $db2), so when the punbb (extern) code tries to run, it's simply pointing at the wrong database. In other words, punbb relies on the author not switching php/mysql to another database, whether explicitly or implicitly.

I can't believe I'm the only person to come across this. Surely other people are integrating punbb into their pages along with their own scripts?

Any ideas? (Thanks for your help so far)

Alan

Re: Error: Unable to fetch group info.

PunBB doesn't rely on that though, it stores the connection ID and uses it explicitly. wink
Now, time to re-read this topic.

Re: Error: Unable to fetch group info.

OK, could you post your complete code so we can take a look at how the scripts are potentially interacting?

Re: Error: Unable to fetch group info.

SORRY. I screwed up.

I went back and discovered that previously I'd disabled the call to the database layer in extern.php, as well as to config.php.
I did this as an over-reaction to errors that I was getting due to calling functions.php twice (which I have now disabled).

Big apologies and thanks to elbekko, Smartys and Rickard for your help.
This hasn't been a fruitless exercise for me, I've learned how to use db objects, and not to be so heavy handed with comment tags!

Alan