error message that says mysql_real_escape_string() expects parameter 2....

Started by Quexinos, February 23, 2011, 12:03:19 AM

Previous topic - Next topic

Quexinos

Okay so even though my forum isn't that busy, I sometimes get an error that says it can't connect to the database because it might be too busy.  My host said it was probably too many people contacting the database at once, but this seems weird to me because it's not that busy of a forum  :-\

The only thing I noticed was in my error logs it says:
[21-Feb-2011 16:00:15] PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php on line 143

over and over and over and over and many many many times .  I'm wondering if this is somehow causing the issue... does anyone know how to fix this?

Quexinos

Bump.  You know what?  All these errors started the day I installed the 4.0 Security Patch ... maybe there's something wrong with it?

Arantor

There isn't, since I'm also running just that patch (mind you I made it work on my modified RC3) but the patch is not something that would cause DB errors, it fixes issues in SSI and manage news.

What mods do you have?
Holder of controversial views, all of which my own.


mabley

I have the same problem!  We were getting so many database errors that our 10 or so users couldn't really use the forums.  We've taken the measures to get rid of spammers such as Arantor's fix, Honeypot and HttpBL, and that has solved our log-out issues, but our database errors continue to be a problem.

I asked my host about it and they responded with this message:

QuoteIt appears that you are currently using FastCGI.  The first thing to do would be to make sure that both Mediawiki and SMF are compatible with running php as FastCGI.  Some programs aren't.  For example, I know some third party components for Joomla don't work that way.  If that's the case, you'll need to run PHP5 (Single php.ini).  Also, I looked at the end of the error_log and saw this:

"[22-Feb-2011 09:50:16] PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /home3/absitome/public_html/Sources/Subs-Db-mysql.php on line 143"

So, it looks like there's a problem with the syntax of the code.  I would investigate that error since it is repeated over and over again.

I don't know what this means, honestly. :( Can anyone help?

Details about my forum:
Quote
Powered by SMF 2.0 RC4
SimplePortal 2.3.3
SubAccounts Mod
Add Honey Pot to Track IP
Bad Behavior Mod
Login Detector
HttpBL
Stop Spammer

Order Custom Profile Fields
Custom Form Mod
Footnotes
Drafts
Signature Image Rotator
Bakers Dozen Pages
SMF Links
Tagging System



Arantor

SMF is compatible running through FastCGI - a number of the larger board owners are doing so.

I am beginning to get a bit concerned about these mysql_real_escape_string errors though.
Holder of controversial views, all of which my own.


Quexinos

Quote from: Arantor on February 23, 2011, 08:05:01 AM
There isn't, since I'm also running just that patch (mind you I made it work on my modified RC3) but the patch is not something that would cause DB errors, it fixes issues in SSI and manage news.

What mods do you have?
It's not a mod.  Too many people are having this problem with different mods for it to be a mod.
But, here are the mods I'm using anyway:
Quote1.    Advanced Reputation System    1.8.1    
2.    Simple Spoiler    1.0    
3.    YouTube BBCode    2.6    
4.    SMFShop    3.1.6.1
5.    SMF Gallery Lite    3.0.2    
6.    Auto Refresh Who Index    1.0    
7.    SMF Articles    1.3.3
8.    More Spiders    1.2
9.    Stop Forum Spam    0.6
10.    SMF 2.0 RC4 Security Patch    1.0    
11.    Regular smileys to dark background smiley set    1.0

and to prove a point, here's my error log from this morning.  The error happened over 10,000 times in a MINUTE.  That's insane... there's no way a mod can do that... at least I hope so :(

Sorry but I'm getting a little frustrated that several of us are having these problems and no one seems to know how to fix it.  There has to be someone.  :(

Arantor

QuoteIt's not a mod.  Too many people are having this problem with different mods for it to be a mod.

I disagree. The most common factor previously was high load (since the function in question requires a DB connection), and I was looking for mods that have a high load about them, like Enotify - or other mods that refresh the page...

Actually, yes there are plenty of ways for mods to screw up a forum - a mod is nothing more than raw code inserted at the right point in the source, they can do quite literally anything.


QuoteSorry but I'm getting a little frustrated that several of us are having these problems and no one seems to know how to fix it.  There has to be someone.

Gee, thanks for making me feel like I have some idea what I'm talking about. Even the best doctor in the world can't diagnose the illness of a patient he's never seen, with a symptom that on its own makes no sense whatsoever...

I have to say, that error log didn't help, all it did was quote the same error over and over, it doesn't provide any more information on actually nailing down the problem.

FWIW, I have the patch installed as well, and I'm not seeing the problem at all. (I did have a look at the development stages of the patch and I see no reason for it to be triggering based on anything in the patch, not even with the first drafts of it)

So, looking at the error it's actually giving, it's failing because $connection isn't a connection resource but is a boolean. Since that's defined through smf_db_quote in the DB AL... the only reason I can think of is if there's something really weird going on with the DB connection.

So, what version of SMF, what version of PHP, what version of MySQL, and is this error in the forum error log at all (and if so, the full details will be really handy)?
Holder of controversial views, all of which my own.


Quexinos

QuoteI disagree. The most common factor previously was high load (since the function in question requires a DB connection), and I was looking for mods that have a high load about them, like Enotify - or other mods that refresh the page...
Well I just meant we all didn't have a mod in common, I know mods can screw things up but wouldn't we all have to have the same one?

QuoteGee, thanks for making me feel like I have some idea what I'm talking about. Even the best doctor in the world can't diagnose the illness of a patient he's never seen, with a symptom that on its own makes no sense whatsoever...
No you're doing fine, I'm sorry.   Like I said I'm just frustrated that this has been going on for almost a week and so far no solution or ideas have been given. 

QuoteSo, what version of SMF, what version of PHP, what version of MySQL, and is this error in the forum error log at all (and if so, the full details will be really handy)?
SMF 2.0 RC 4 (with the security patch)
PHP my admin:  3.3.9
MySQL client version: 5.1.52 (is that what you need?)

and I'm not sure what your question means, that's the error log in its entirety if that's what you're asking.

Arantor

QuoteWell I just meant we all didn't have a mod in common, I know mods can screw things up but wouldn't we all have to have the same one?

Well, since no-one other than you bothered to post what mods you had, you may well have a mod in common for all I know...

QuoteLike I said I'm just frustrated that this has been going on for almost a week and so far no solution or ideas have been given. 

You're not the only one frustrated.

QuoteSMF 2.0 RC 4 (with the security patch)
PHP my admin:  3.3.9
MySQL client version: 5.1.52 (is that what you need?)

OK so that tells me what SMF version, and it sort of explains the MySQL version since phpMyAdmin would be complaining bitterly by now if you had a different client version to server version.

But as for PHP version, I need to know what version of the PHP interpreter you're using, which phpMyAdmin doesn't tell you. SMF does, if you can get into the admin panel, in the 'more detailed' link on the right under 'Support Information'.

Quotethat's the error log in its entirety if that's what you're asking.

No, that's not what I'm asking for. SMF maintains its own error log in the admin panel. I was hoping the error was logged in there, a little unlikely maybe, but I figured it didn't hurt to give it a go to ask. If it *is* logged in there, there's a chance we can get some more debug information on it.
Holder of controversial views, all of which my own.


Quexinos

QuoteYou're not the only one frustrated.
You're right, I guess we're all frustrated.  I shouldn't be taking it out on you, you're trying to help.

QuoteBut as for PHP version, I need to know what version of the PHP interpreter you're using, which phpMyAdmin doesn't tell you. SMF does, if you can get into the admin panel, in the 'more detailed' link on the right under 'Support Information'.
Lemme attach a screenshot here...

QuoteNo, that's not what I'm asking for. SMF maintains its own error log in the admin panel. I was hoping the error was logged in there, a little unlikely maybe, but I figured it didn't hurt to give it a go to ask. If it *is* logged in there, there's a chance we can get some more debug information on it.
I'm afraid I don't see it... but apparently something is wrong with my spoiler mod. 

This error comes up a lot:
Apply Filter: Only show the error messages of this URL
http://www.equestriaforums.com/index.php?topic=64.new
Apply Filter: Only show the errors with the same message
8: Undefined variable: user_info
Apply Filter: Only show the errors from this file
File: /home/nepta/public_html/equestriaforums.com/Themes/default/languages/SimpleSpoiler.english.php (main sub template - eval?)
Line: 382

Think that has anything to do with it?

feline

content removed

Arantor

QuoteLemme attach a screenshot here...

Oops. I was thinking of the wrong thing.

Admin > Main > Support and Credits.

Has a block at the top which lists like so:

QuoteVersion Information:
Forum version: SMF 2.0 RC4 (more detailed)
Current SMF version: SMF 2.0 RC5
GD version: bundled (2.0.34 compatible)
MySQL version: 5.1.48-community
PHP: 5.2.13
Server version: Apache/2.2.15 (Win32) PHP/5.2.13


@fel Other users are quoting this and it doesn't seem like there are mods in common at the moment, save for ones that have a reasonably high load potential.
Holder of controversial views, all of which my own.


Quexinos

Version Information:
Forum version: SMF 2.0 RC4 (more detailed)
Current SMF version: SMF 2.0 RC5
GD version: bundled (2.0.34 compatible)
MySQL version: 5.1.52
PHP: 5.2.15
Server version: Apache mod_fcgid/2.3.6 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635

there you go ^_^
BTW if you want I'll totally give you admin powers at my forum if you wanna poke around.  Dunno if that'll help or not.

Arantor

I don't think having admin access would help at this point :(

Is it still happening/ongoing, or does it happen in bursts? (I've ruled out a few things it could be now I know the PHP version, which is something)

If it happens again, it would be worth making this change, to see what's going on. This is to Subs-Db-Mysql.php as mentioned in the error, only it happens a touch earlier in the process.

Code (find) Select
list ($values, $connection) = $db_callback;

Code (replace) Select
if (!is_resource($connection))
{
ob_start();
var_dump(debug_backtrace());
var_dump($connection);
$content = ob_end_clean();
die('Something very bad happened, please advise the administrator of: ' . $content);
}
list ($values, $connection) = $db_callback;


$connection is the second parameter to mysql_real_escape_string and it's supposed to be a resource, but for some reason it's not. So if it's not a resource, catch it ahead of the game, grab the list of 'backtrace', which will tell us the hierarchy of function calls that got us to this point (to trace execution) and what $connection is at that point, and maybe we can make some sense of it.

It won't be very pretty, and it will end processing there and then, but with any luck it'll give us something useful to work with.
Holder of controversial views, all of which my own.


Quexinos

Uhm...

Quote
Strict Standards: smf_db_replacement__callback() [function.smf-db-replacement--callback]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead in /home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php on line 114

Notice: Undefined variable: connection in /home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php on line 114
Something very bad happened, please advise the administrator of: 1

when I uploaded it
... also I think you gave me the wrong function, shouldn't it be

if (!is_resource($connection))
{
ob_start();
var_dump(debug_backtrace());
var_dump($connection);
$content = ob_get_contents();
ob_end_clean();
die('Something very bad happened, please advise the administrator of: ' . $content);
}

?

I got a stack trace with that.

Quexinos

lol, I dunno but here's my stack trace:

Something very bad happened, please advise the administrator of: array(12) {
  [0]=>
  array(2) {
    ["function"]=>
    string(28) "smf_db_replacement__callback"
    ["args"]=>
    array(1) {
      [0]=>
      &array(3) {
        [0]=>
        string(15) "{int:id_member}"
        [1]=>
        string(3) "int"
        [2]=>
        string(9) "id_member"
      }
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
    ["line"]=>
    int(231)
    ["function"]=>
    string(21) "preg_replace_callback"
    ["args"]=>
    array(3) {
      [0]=>
      &string(35) "~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~"
      [1]=>
      &string(28) "smf_db_replacement__callback"
      [2]=>
      &string(223) "({int:id_member}, {int:log_time}, SUBSTRING({string:ip}, 1, 16), SUBSTRING({string:url}, 1, 65534), SUBSTRING({string:message}, 1, 65534), {string:session}, {string:error_type}, SUBSTRING({string:file}, 1, 255), {int:line})"
    }
  }
  [2]=>
  array(4) {
    ["file"]=>
    string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
    ["line"]=>
    int(644)
    ["function"]=>
    string(12) "smf_db_quote"
    ["args"]=>
    array(3) {
      [0]=>
      &string(223) "({int:id_member}, {int:log_time}, SUBSTRING({string:ip}, 1, 16), SUBSTRING({string:url}, 1, 65534), SUBSTRING({string:message}, 1, 65534), {string:session}, {string:error_type}, SUBSTRING({string:file}, 1, 255), {int:line})"
      [1]=>
      &array(9) {
        ["id_member"]=>
        int(0)
        ["log_time"]=>
        int(1298518301)
        ["ip"]=>
        string(0) ""
        ["url"]=>
        string(1) "?"
        ["message"]=>
        string(33) "8: Undefined variable: connection"
        ["session"]=>
        string(0) ""
        ["error_type"]=>
        string(14) "undefined_vars"
        ["file"]=>
        string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
        ["line"]=>
        int(114)
      }
      [2]=>
      &resource(8) of type (mysql link)
    }
  }
  [3]=>
  array(4) {
    ["file"]=>
    string(62) "/home/nepta/public_html/equestriaforums.com/Sources/Errors.php"
    ["line"]=>
    int(155)
    ["function"]=>
    string(13) "smf_db_insert"
    ["args"]=>
    array(5) {
      [0]=>
      &string(0) ""
      [1]=>
      &string(21) "{db_prefix}log_errors"
      [2]=>
      &array(9) {
        ["id_member"]=>
        string(3) "int"
        ["log_time"]=>
        string(3) "int"
        ["ip"]=>
        string(9) "string-16"
        ["url"]=>
        string(12) "string-65534"
        ["message"]=>
        string(12) "string-65534"
        ["session"]=>
        string(6) "string"
        ["error_type"]=>
        string(6) "string"
        ["file"]=>
        string(10) "string-255"
        ["line"]=>
        string(3) "int"
      }
      [3]=>
      &array(9) {
        [0]=>
        int(0)
        [1]=>
        int(1298518301)
        [2]=>
        string(0) ""
        [3]=>
        string(1) "?"
        [4]=>
        string(33) "8: Undefined variable: connection"
        [5]=>
        string(0) ""
        [6]=>
        string(14) "undefined_vars"
        [7]=>
        string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
        [8]=>
        int(114)
      }
      [4]=>
      &array(1) {
        [0]=>
        string(8) "id_error"
      }
    }
  }
  [4]=>
  array(4) {
    ["file"]=>
    string(62) "/home/nepta/public_html/equestriaforums.com/Sources/Errors.php"
    ["line"]=>
    int(263)
    ["function"]=>
    string(9) "log_error"
    ["args"]=>
    array(4) {
      [0]=>
      &string(33) "8: Undefined variable: connection"
      [1]=>
      &string(14) "undefined_vars"
      [2]=>
      &string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
      [3]=>
      &int(114)
    }
  }
  [5]=>
  array(4) {
    ["file"]=>
    string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
    ["line"]=>
    int(114)
    ["function"]=>
    string(13) "error_handler"
    ["args"]=>
    array(5) {
      [0]=>
      &int(8)
      [1]=>
      &string(30) "Undefined variable: connection"
      [2]=>
      &string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
      [3]=>
      &int(114)
      [4]=>
      &array(4) {
        ["matches"]=>
        array(2) {
          [0]=>
          string(11) "{db_prefix}"
          [1]=>
          string(9) "db_prefix"
        }
        ["db_callback"]=>
        &array(2) {
          [0]=>
          array(9) {
            ["id_member"]=>
            int(0)
            ["log_time"]=>
            int(1298518301)
            ["ip"]=>
            string(0) ""
            ["url"]=>
            string(1) "?"
            ["message"]=>
            string(33) "8: Undefined variable: connection"
            ["session"]=>
            string(0) ""
            ["error_type"]=>
            string(14) "undefined_vars"
            ["file"]=>
            string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
            ["line"]=>
            int(114)
          }
          [1]=>
          resource(8) of type (mysql link)
        }
        ["user_info"]=>
        &array(2) {
          ["id"]=>
          int(0)
          ["ip"]=>
          string(0) ""
        }
        ["db_prefix"]=>
        &string(4) "mlp_"
      }
    }
  }
  [6]=>
  array(2) {
    ["function"]=>
    string(28) "smf_db_replacement__callback"
    ["args"]=>
    array(1) {
      [0]=>
      &array(2) {
        [0]=>
        string(11) "{db_prefix}"
        [1]=>
        string(9) "db_prefix"
      }
    }
  }
  [7]=>
  array(4) {
    ["file"]=>
    string(69) "/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php"
    ["line"]=>
    int(286)
    ["function"]=>
    string(21) "preg_replace_callback"
    ["args"]=>
    array(3) {
      [0]=>
      &string(35) "~{([a-z_]+)(?::([a-zA-Z0-9_-]+))?}~"
      [1]=>
      &string(28) "smf_db_replacement__callback"
      [2]=>
      &string(92) "
SELECT data
FROM {db_prefix}sessions
WHERE session_id = {string:session_id}
LIMIT 1"
    }
  }
  [8]=>
  array(4) {
    ["file"]=>
    string(60) "/home/nepta/public_html/equestriaforums.com/Sources/Load.php"
    ["line"]=>
    int(2490)
    ["function"]=>
    string(12) "smf_db_query"
    ["args"]=>
    array(3) {
      [0]=>
      &string(0) ""
      [1]=>
      &string(92) "
SELECT data
FROM {db_prefix}sessions
WHERE session_id = {string:session_id}
LIMIT 1"
      [2]=>
      &array(1) {
        ["session_id"]=>
        string(32) "2ccb9bba8cd2bf4c2c48ae8bd7538121"
      }
    }
  }
  [9]=>
  array(2) {
    ["function"]=>
    string(11) "sessionRead"
    ["args"]=>
    array(1) {
      [0]=>
      &string(32) "2ccb9bba8cd2bf4c2c48ae8bd7538121"
    }
  }
  [10]=>
  array(4) {
    ["file"]=>
    string(60) "/home/nepta/public_html/equestriaforums.com/Sources/Load.php"
    ["line"]=>
    int(2444)
    ["function"]=>
    string(13) "session_start"
    ["args"]=>
    array(0) {
    }
  }
  [11]=>
  array(4) {
    ["file"]=>
    string(53) "/home/nepta/public_html/equestriaforums.com/index.php"
    ["line"]=>
    int(115)
    ["function"]=>
    string(11) "loadSession"
    ["args"]=>
    array(0) {
    }
  }
}

<br />
<b>Notice</b>:  Undefined variable: connection in <b>/home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php</b> on line <b>118</b><br />
NULL


is that what you need?

Quexinos

Okay so is what I posted no good?  Do I need to do it again?

I think that the problem is "connection" is undefined so it doesn't really matter when list gets called. I think anyway, I'm not an expert  :P

Quexinos

Okay I think I misunderstood what the goal was here, my bad.

Okay I'll set it up like you said... shouldn't take too long since these errors seem to come up a lot lately.

Arantor

Actually, the line should have been ob_get_clean not ob_end_clean ;) To be fair it was gone 2am...

Anyway, the code was supposed to be added above the list() line (which is why I left it in the replace), and unfortunately that stack trace just tells me the list() line was removed :(
Holder of controversial views, all of which my own.


Quexinos

OKay so I have

list ($values, $connection) = $db_callback;

if (!is_resource($connection))
{
ob_start();
var_dump(debug_backtrace());
var_dump($connection);
$content = ob_get_contents();
ob_end_clean();
die('Something very bad happened, please advise the administrator of: ' . $content);
}


and you're saying it should be




    if (!is_resource($connection))
{
ob_start();
var_dump(debug_backtrace());
var_dump($connection);
$content = ob_get_clean();
die('Something very bad happened, please advise the administrator of: ' . $content);
}

list ($values, $connection) = $db_callback;


because when I do it that way I get this error on the forum:

QuoteStrict Standards: require_once() [function.require-once]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-6.0/no DST' instead in /home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php on line 729

Parse error: syntax error, unexpected $end in /home/nepta/public_html/equestriaforums.com/Sources/Subs-Db-mysql.php on line 729
which is confusing because it doesn't go up to 729 O_o

EDIT

actually I just tried it again and got a big list like before, I'll attach it but I think it's the same as before

Advertisement: