1 (edited by an.archi 2007-09-23 09:45)

Topic: supplied argument is not a valid MySQL result resource

Hi everybody.

We ran into a small bug/problem lately on our PunBB forum: http://archiforum.free.fr/.
After a few long posts in the same thread, we had this error message (only on this thread):

Fatal error: mysql_free_result(): supplied argument is not a valid MySQL result resource in /mnt/166/sdb/8/9/archiforum/include/dblayer/mysql.php on line 185

I guess this means the MySQL request has been terminated too early, right?

Actually, the only solution I found was to reduce the number of posts per thread, so that the request doesn't fail.
If I clean the "cache" folder, I can see the thread with the first post only in it, then when one refreshes it, there goes the error report again.

I created a dummy account where I asked for 25 posts per thread (the previous settings for default user options) if you want to check (the code is "2ufn9XNG" and this account is read-only).

Thanks for any help if this weird situation doesn't come from PunBB, or thanks to fix this issue whenever you can (if it's a bug, of course). :)

Re: supplied argument is not a valid MySQL result resource

Could you paste your code at around that line?

Re: supplied argument is not a valid MySQL result resource

Of course. :)
mmm, I did change this file for PBB Gallery

- added line 114:

[line 113]
    function fetch_array($query_id = 0)
    {
        return ($query_id) ? @mysql_fetch_array($query_id) : false;
    }
[line 179]
    function close()
    {
        if ($this->link_id)
        {
            if ($this->query_result)
                @mysql_free_result($this->query_result);

            return @mysql_close($this->link_id);
        }
        else
            return false;
    }
}
[EOF]

But I don't see why it could break anything... :/

any clue ?

Re: supplied argument is not a valid MySQL result resource

Now that doesn't make sense, for two reasons:
1. $this->query_result should be a resource, that's what the if statement is for.
2. According to the documentation for mysql_free_result, you should only see a warning.
3. Using the @ should suppress any error you might see anyway.

Try changing if ($this->query_result) to if (is_resource($this->query_result))

Re: supplied argument is not a valid MySQL result resource

If only it was that simple for me to change this. smile
Free doesn't allow people out of France to access their FTP server, so it's getting a bit complicated to work on this site.
(If you know any French FTP proxy, I'm interested)

Anyway, it's done but doesn't change anything, unfortunately.

Re: supplied argument is not a valid MySQL result resource

Looks "fixed" to me, you have a new error now. wink

Re: supplied argument is not a valid MySQL result resource

mmm, nope.
Exactly the same error.

Do you use the account named "Fabien" or do you just look at the thread as a guest?
As I explained before, the default settings now is 15 posts seen per thread, and it's working nice.

But if the user (Fabien) sets it to 25 (the default setting for PunBB?)... CRAAASH !
Looks like there is too much data.

Re: supplied argument is not a valid MySQL result resource

Mmm, how odd. I was getting an error about the quickjump cache file. I'm not now though.
I don't think the issue is too much data.
Could you do me a favor and paste a copy of footer.php?

Re: supplied argument is not a valid MySQL result resource

My suggestion in any case would be just to comment out the lines that refer to mysql_free_result, since it appears the host has some trouble with it (I managed to find another site with a difference piece of software with the same issue on free.fr using Google).

Re: supplied argument is not a valid MySQL result resource

Here we go:

<?php
/***********************************************************************
[... copyright Rickard Andersson...]
************************************************************************/


// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_main>', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <pun_main>


// START SUBST - <pun_footer>
ob_start();

?>
<div id="brdfooter" class="block">
    <h2><span><?php echo $lang_common['Board footer'] ?></span></h2>
    <div class="box">
        <div class="inbox">
<?php

// If no footer style has been specified, we use the default (only copyright/debug info)
$footer_style = isset($footer_style) ? $footer_style : NULL;

if ($footer_style == 'index' || $footer_style == 'search')
{
    if (!$pun_user['is_guest'])
    {
        echo "\n\t\t\t".'<dl id="searchlinks" class="conl">'."\n\t\t\t\t".'<dt><strong>'.$lang_common['Search links'].'</strong></dt>'."\n\t\t\t\t".'<dd><a href="search.php?action=show_24h">'.$lang_common['Show recent posts'].'</a></dd>'."\n";
        echo "\t\t\t\t".'<dd><a href="search.php?action=show_unanswered">'.$lang_common['Show unanswered posts'].'</a></dd>'."\n";

        if ($pun_config['o_subscriptions'] == '1')
            echo "\t\t\t\t".'<dd><a href="search.php?action=show_subscriptions">'.$lang_common['Show subscriptions'].'</a></dd>'."\n";

        echo "\t\t\t\t".'<dd><a href="search.php?action=show_user&user_id='.$pun_user['id'].'">'.$lang_common['Show your posts'].'</a></dd>'."\n\t\t\t".'</dl>'."\n";
    }
    else
    {
        if ($pun_user['g_search'] == '1')
        {
            echo "\n\t\t\t".'<dl id="searchlinks" class="conl">'."\n\t\t\t\t".'<dt><strong>'.$lang_common['Search links'].'</strong></dt><dd><a href="search.php?action=show_24h">'.$lang_common['Show recent posts'].'</a></dd>'."\n";
            echo "\t\t\t\t".'<dd><a href="search.php?action=show_unanswered">'.$lang_common['Show unanswered posts'].'</a></dd>'."\n\t\t\t".'</dl>'."\n";
        }
    }
}
else if ($footer_style == 'viewforum' || $footer_style == 'viewtopic')
{
    echo "\n\t\t\t".'<div class="conl">'."\n";

    // Display the "Jump to" drop list
    if ($pun_config['o_quickjump'] == '1')
    {
        // Load cached quickjump
        @include PUN_ROOT.'cache/cache_quickjump_'.$pun_user['g_id'].'.php';
        if (!defined('PUN_QJ_LOADED'))
        {
            require_once PUN_ROOT.'include/cache.php';
            generate_quickjump_cache($pun_user['g_id']);
            require PUN_ROOT.'cache/cache_quickjump_'.$pun_user['g_id'].'.php';
        }
    }

    if ($footer_style == 'viewforum' && $is_admmod)
        echo "\t\t\t".'<p id="modcontrols"><a href="moderate.php?fid='.$forum_id.'&p='.$p.'">'.$lang_common['Moderate forum'].'</a></p>'."\n";
    else if ($footer_style == 'viewtopic' && $is_admmod)
    {
        echo "\t\t\t".'<dl id="modcontrols"><dt><strong>'.$lang_topic['Mod controls'].'</strong></dt><dd><a href="moderate.php?fid='.$forum_id.'&tid='.$id.'&p='.$p.'">'.$lang_common['Delete posts'].'</a></dd>'."\n";
        echo "\t\t\t".'<dd><a href="moderate.php?fid='.$forum_id.'&move_topics='.$id.'">'.$lang_common['Move topic'].'</a></dd>'."\n";

        if ($cur_topic['closed'] == '1')
            echo "\t\t\t".'<dd><a href="moderate.php?fid='.$forum_id.'&open='.$id.'">'.$lang_common['Open topic'].'</a></dd>'."\n";
        else
            echo "\t\t\t".'<dd><a href="moderate.php?fid='.$forum_id.'&close='.$id.'">'.$lang_common['Close topic'].'</a></dd>'."\n";

        if ($cur_topic['sticky'] == '1')
            echo "\t\t\t".'<dd><a href="moderate.php?fid='.$forum_id.'&unstick='.$id.'">'.$lang_common['Unstick topic'].'</a></dd></dl>'."\n";
        else
            echo "\t\t\t".'<dd><a href="moderate.php?fid='.$forum_id.'&stick='.$id.'">'.$lang_common['Stick topic'].'</a></dd></dl>'."\n";
    }

    echo "\t\t\t".'</div>'."\n";
}

?>
            <p class="conr">Powered by <a href="http://www.punbb.org/">PunBB</a><?php if ($pun_config['o_show_version'] == '1') echo ' '.$pun_config['o_cur_version']; ?><br />© Copyright 2002–2005 Rickard Andersson</p>
<?php

// Display debug info (if enabled/defined)
if (defined('PUN_DEBUG'))
{
    // Calculate script generation time
    list($usec, $sec) = explode(' ', microtime());
    $time_diff = sprintf('%.3f', ((float)$usec + (float)$sec) - $pun_start);
    echo "\t\t\t".'<p class="conr">[ Generated in '.$time_diff.' seconds, '.$db->get_num_queries().' queries executed ]</p>'."\n";
}

?>
            <div class="clearer"></div>
        </div>
    </div>
</div>
<?php


// End the transaction
$db->end_transaction();

// Display executed queries (if enabled)
if (defined('PUN_SHOW_QUERIES'))
    display_saved_queries();

$tpl_temp = trim(ob_get_contents());
$tpl_main = str_replace('<pun_footer>', $tpl_temp, $tpl_main);
ob_end_clean();
// END SUBST - <pun_footer>


// START SUBST - <pun_include "*">
while (preg_match('#<pun_include "([^/\\\\]*?)">#', $tpl_main, $cur_include))
{
    if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1]))
        error('Unable to process user include <pun_include "'.htmlspecialchars($cur_include[1]).'"> from template main.tpl. There is no such file in folder /include/user/');

    ob_start();
    include PUN_ROOT.'include/user/'.$cur_include[1];
    $tpl_temp = ob_get_contents();
    $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
    ob_end_clean();
}
// END SUBST - <pun_include "*">


// Close the db connection (and free up any result data)
$db->close();

// Spit out the page
exit($tpl_main);

I will try the comments, thanks for the answers.