News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

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

VividViews

In case anyone was wondering...

Version Information:

Forum version: SMF 2.0 (more detailed)
Current SMF version: SMF 2.0
GD version: bundled (2.0.34 compatible)
MySQL version: 5.0.90-community
PHP: 5.2.17
Server version: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4



Mods:

1. Facebook Video BBC 1.0
2. Facebook_Like v.2.0 2.0
3. Pretty URLs Extras 1.0
4. Pretty URLs 1.0RC4
5. Newsletter Pro 2.0.7
6. SMF Gallery Pro - Video AddOn 3.5.2
7. SMF Gallery Pro SSI 2.1.1
8. Dream Menu 1.0.6
9. EzPortal 0.5.1
10. SMF Gallery Pro 3.0.25
11. reCAPTCHA for SMF 0.9.8a
12. Spiders Don't Increase Topic Views 1.1.1
13. Admin Notepad 2.0.1


I can also post the output of the SMF tool "status.php" and phpinfo() if requested

luuuciano

Quote from: IncognitoMuse on February 26, 2011, 06:41:46 PM
If that IS needed, which I'm not 100% sure on, the code would be as follows in Errors.php:
Code (find) Select
function show_db_error($loadavg = false)
{
global $sourcedir, $mbname, $maintenance, $mtitle, $mmessage, $modSettings;
global $db_connection, $webmaster_email, $db_last_error, $db_error_send, $smcFunc;


Code (after that, add) Select
// Just check we're not in any buffers, just in case.
for ($i = ob_get_level(); $i > 0; $i--)
@ob_end_clean();


Adding that the error_log file fills of:
[18-Sep-2011 16:03:02] PHP Warning:  Cannot modify header information - headers already sent in /home/username/public_html/Sources/Errors.php on line 346
[18-Sep-2011 16:03:02] PHP Warning:  Cannot modify header information - headers already sent in /home/username/public_html/Sources/Errors.php on line 347
[18-Sep-2011 16:03:02] PHP Warning:  Cannot modify header information - headers already sent in /home/username/public_html/Sources/Errors.php on line 348
[18-Sep-2011 16:03:02] PHP Warning:  Cannot modify header information - headers already sent in /home/username/public_html/Sources/Errors.php on line 351
[18-Sep-2011 16:03:02] PHP Warning:  Cannot modify header information - headers already sent in /home/username/public_html/Sources/Errors.php on line 352
[18-Sep-2011 16:03:02] PHP Warning:  Cannot modify header information - headers already sent in /home/username/public_html/Sources/Errors.php on line 353

It will be ok to put them after all the header lines below that? any other solution?


BTW, this error hits me too!
What a bad trip!
(Or maybe we can say "what a bad loop")

I am in a shared hostgator account too... The time when it happened I was configuration the PMxSubforum mod, so I thought it was that... the server admins banned limited the max_questions amount to just 1, so I can not tested enything until I replied their issue ticked, asking for a time to test the changes made on those files...

BTW2, my first atemp was to try this: http://www.sergechel.info/articles/fix_smf_error_mysql_real_escape_string_expects_parameter_2_be_resource_boolean_given
as it was the 1st thing a found...
Anyway, my acount were banned at this time, and can not test it at all
No me agradan los foros que no te dejan borrar TU PROPIO usuario, como por ejemplo smfsimple.com.
E incluso te mandan emails no solicitados, de los cuales, quizá, no puedas escapar porque NO te dejan posibilidad a deshabilitarlos (a menos que NO te tengan en su lista negra).

Illori

please open a separate topic for your issue, this thread belongs to someone else and is old so things may have changed since then.

luuuciano

Quote from: Illori on September 18, 2011, 03:32:53 PM
please open a separate topic for your issue, this thread belongs to someone else and is old so things may have changed since then.

w00t?

I just see that it is happening in 2.0 gold too...

The error loop continue there, and it was not added any code like the one suggested by arantor to bypass the massive error_log creation and server hammering when things went sour on smf/server/spiders/members/whatever

This was the only thread where I found people trying to understand what was going on and trying to solve it (anyway, maybe I have missed others in my search)
No me agradan los foros que no te dejan borrar TU PROPIO usuario, como por ejemplo smfsimple.com.
E incluso te mandan emails no solicitados, de los cuales, quizá, no puedas escapar porque NO te dejan posibilidad a deshabilitarlos (a menos que NO te tengan en su lista negra).

Illori

we request each user to have their own thread for their issue so we can make sure it is resolved by posting in someone elses thread we can not make sure your issue is resolved.

ArticleProductions

 I have my own thread, seems this error is more of a problem than what most thought.

I have a dedicated server and still have this issue with 2.0.1

http://www.simplemachines.org/community/index.php?topic=457261.0

DarkAngel612

yes I know this is an old thread...
my new thread: http://www.simplemachines.org/community/index.php?topic=471886.msg3299241#msg3299241

however although it seems that we all seem to have different mods except maybe a few with the stop spammer mod with httbl and stop forum spam the majority of the posters here are with hostgator.

I too am with them but not shared....I am on a VPS with several forums, a store w/forum and the only one to get this bunch of errors is the main asylum...lol

NEVER had this with smf versions and only started about 2 weeks after installing 2.02.

Is there any other findings. I will try the coding that was last written by Arantor but just curious as to why it would do this with 2.0+ of SMF and not the prior versions with same quantity of use...btw we are not a large forum and get more hits at the market and market forum but this one and the others do not have this problem.

It went away after i fixed an error with undefined text for one of the themes. I did notice that this time the error coincides with another undefined text error in the subs-post file I think along with several other undefined index errors in the subs-post file as php errors. I will list them in my new post.
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

luuuciano

On this thread http://www.simplemachines.org/community/index.php?topic=470276.0 I asked for a way to catch wrong things, and I found this script http://forge.mysql.com/tools/tool.php?id=38
I found the recurrent sql query that was killing mysqld... maybe you can use something similar, to see where is the problem located

My problem was easy to catch (once I realized how to), as it happened on almost every boardindex load...
No me agradan los foros que no te dejan borrar TU PROPIO usuario, como por ejemplo smfsimple.com.
E incluso te mandan emails no solicitados, de los cuales, quizá, no puedas escapar porque NO te dejan posibilidad a deshabilitarlos (a menos que NO te tengan en su lista negra).

DarkAngel612

well as I have noticed, it seems that the error in the servers error log seems to be abundant ONLY after there is a  "breach" in the coding ...like the themes having issues with undefined whatever.

Again this time once I fixed the undefined  text ($txt to $text) and another undefined  index:label by adding the item to the proper language file the error is at bay once more.

Weird that it never did this in the previous versions and that it is set up exactly (give or take a few mods) but settings and all are exactly as the other 4 on our VPS and it is only the one that gets the problems...yes they also have the same themes too.

I also noticed that when checking versions of files from admin of the problem site that it claimed to have an outdated file. After checking then downloading the SMF files again I saw that there was no 2.0.2 file in the zip...there is only the 2.0 files so I went to the file and just added the .2 to that file and the  files all show up to date now....it was the PersonalMessage.template.php file....in the zip it is only 2.0 NOT 2.0.2 but comes up as being outdated version.

I would try what you say but unfortunately I am an idiot and have no clue how to do it...LOL
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

Vince S

Hmm, came here because of this same error, it repeats about 40 times a second, error log file 48Mb, About to delete it. With SiteGround (shared):
PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /home/hunterdo/public_html/DiscussionBoard/Sources/Subs-Db-mysql.php on line 132
[09-Apr-2012 04:01:02].

No mods on this site, a month back or so did a major re-upgrade to sort another problem, at latest 2.0.2 version. Currently have some (presumably) other issue stopping me seeing any SQL based add-ons (smf, calendar, photo gallery) which gets a "The connection to the server was reset while the page was loading". I am about to ask SiteGround about that as it has been going some hours, I was just checking what files changed recently and it is only the error log in the smf folder, hence I opened it and found this mess. Just mentioning in case this isn't a coincidence or jogs another's problem solving idea into life. Will advise if I figure anything else out myself in the interim.........
Try figuring out where all this is going to keep coming from: Millionaire Baby? Or just pass me a beer and we'll sort it, thank you.....

DarkAngel612

ok, I was still having the same trouble...4 forums with 2.02/TinyPortal/various mods and only 1 has that issue

all same vps, same setup and almost same mods but only 1 forum misbehaving with that error so as a last resort I went and removed all files for smf/tp after uninstalling the mods...which am a bit upset cause when I removed the mod my entire folder full of downloads are not  back---even though one can still download them---weird.

did the reup of the fresh files, installed mods and tp and so far (since 11:30 pm Sunday night) to now that error has not been back, keeping fingers crossed.

never got the error when it was 1.1.19 and running the same mods then.
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

Vince S

Well I know a lot more but am not a lot smarter! The server resetting issue was unrelated, it was due to some malware additions to the site that have since been deleted. I have come to the conclusion that shared hosting has malware as a consequence of how it is provided these days and there is stuff all we can do about it as the supposed iron clad means to prevent it are bs, all I don't know is the reason why! For anyone else bugged by this I have found http://sitecheck.sucuri.net/scanner/ to be very useful, but am still balking at paying an annual fee, but my resistance not to do so is almost broken! Anyway that issue was a red herring as far as this thread is concerned.

Looking at the beginning of this thread it may be important to make a clarification. The error I reported was in the php_errorlog file. Since I deleted it yesterday it has grown to 4.4Mb. The error is always the same and occurs 10's of times a second for a variable amount of seconds and a variable rate per second then nothing for typically minutes or hours then out comes another batch. I can't pick a pattern to it of any kind. It would not be too hard to do an excel chart of the frequency if anyone thinks exploring patterns is going to be useful diagnostic work.

I also downloaded and deleted yesterday (at the same time) my error_log file, it had grown to 124Mb in the same time as the php_errorlog file had grown to 48Mb (since I last went round this exercise at beginning of Jan 2012). It also is full of the same error. But here is the really cool thing:

In the php_errorlog these are two adjacent errors:

[16-Mar-2008 06:20:05] PHP Notice:  SSI.php was unable to load a session!  This may cause problems with logout and other functions - please make sure SSI.php is included before *anything* else in all your scripts! in /home/hunterdo/public_html/DiscussionBoard/SSI.php on line 160
[16-Jan-2012 05:18:49] PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /home/hunterdo/public_html/DiscussionBoard/Sources/Subs-Db-mysql.php on line 132

So NOTHING went wrong for nearly 4 years, php wise! and then it was the steady stream of the new error ad nauseum. In fact the first error recurred 8 times prior on the same day and there was nothing earlier. Obviously the first error was fixed by some process i wouldn't now remember, so the question is about what can be done to eliminate the second one that is much more invasive?

Similarly in error_log were these two adjacent errors:

[11-Dec-2007 07:31:37] PHP Warning:  Zend Optimizer for PHP 5.0.x cannot be found (expected at '/usr/local/Zend/lib/Optimizer-3.0.1/php-5.0.x/ZendOptimizer.so') - try reinstalling the Zend Optimizer in Unknown on line 0
[28-
[05-Dec-2011 00:26:15] PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /home/hunterdo/public_html/DiscussionBoard/Sources/Subs-Db-mysql.php on line 132

Same deal, no apparent issues for 4 years and only 8 other errors since Feb 2006 but now we have an unknown truncated error on 28th day of some month before settling down to a never ending stream of an identical but totally unhelpful error.

Why the above two error files do not align is not something I have any idea about, I can only hope this provides a clue to someone more knowledgeable. We moved from from SMF1.1.13 to 2.0RC5 in May 2011, 2.0.1 in September 2011, 2.0.2 in December 2011 just after Chrissie.

Oh dear, I just checked the site error log and it has 492 pages of the following error since Feb 4th 2012 and, at an overall page scanning level, there seems to be reasonable correlation between the frequency of these errors and the ones that are the subject of this thread:
Apply Filter: Only show the error messages of this member Guest
Apply Filter: Only show the error messages of this IP address 175.145.52.245 
     Reverse chronological order of list Yesterday at 04:25 AM
Apply Filter: Only show the error messages of this session 921cb8834049df3afed4ab8c99b88e7c
Apply Filter: Only show the errors of this type Type of error: General
Apply Filter: Only show the error messages of this URL
http://hunterdog.org.au/DiscussionBoard/index.php?topic=234.0;prev_next=next
Apply Filter: Only show the errors with the same message
8: Uninitialized string offset: 0
Apply Filter: Only show the errors from this file
File: /home/hunterdo/public_html/DiscussionBoard/index.php
Line: 374

Does that raise the curtains of clarity for anyone? Thank you.

edit: In case anyone is wondering on the Package Mgr page of the Admin settings we have:
View and Remove Installed Packages
No mods currently installed
Try figuring out where all this is going to keep coming from: Millionaire Baby? Or just pass me a beer and we'll sort it, thank you.....

DarkAngel612

yup same here...no such problem for nearly 4-5 years with even a host move...yet the minute I updated to 2.0.2 it decided to go haywire with that procreating error matching yours:

Quote[16-Jan-2012 05:18:49] PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /home/hunterdo/public_html/DiscussionBoard/Sources/Subs-Db-mysql.php on line 132

same line over and over but so far so good after total uninstalling of mods and manually uploading/replacing smf files I deleted from server it seems to be gone for now.

mine would show up after ANY error in the admin error log of forum, so far now it is gone...for how long I have no clue but am hoping forever...

will see if it stays healthy this weekend and let you know if my drastic measure helped me. May be something to do...weird too that I had to do it since maybe the install of through package manager maybe did not go thoroughly like always...who knows.
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

DarkAngel612

and here I return...LOL

as I said earlier it went away but then came back...yesterday


the only thing that stands out yesterday is the enhanced drop down mod for the font color/size/face menus to be enhanced.

I had removed it earleir but put it back and that is just about when the errors started.

then I thought maybe I could just use parts to be able to see the color choices not just text of choices and that is about when the error started to procreate again.

also when some undefined text---for color choices I added are showing...but no error showing todays date in that procreated log on server..go figure.
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

DarkAngel612

well here is the next batch of errors...the very first one set the mysql error to create itself later on over and over again: I have also included the coding for the section with the line in red.

[15-Apr-2012 03:33:08] PHP Warning:  POST Content-Length of 30739448 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

No clue to what needs done or where to look...it may have sprouted from a member going over the post box limit in shout box (TinyPortal)




[15-Apr-2012 17:32:53] PHP Warning:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given in .../Sources/Subs-Db-mysql.php on line 132


     case 'string':
         case 'text':
            return sprintf('\'%1$s\'', mysql_real_escape_string($replacement, $connection));
         break;





[15-Apr-2012 18:59:18] PHP Warning:  mysql_error(): supplied argument is not a valid MySQL-Link resource in .../Sources/Subs-Db-mysql.php on line 414


[15-Apr-2012 18:59:18] PHP Warning:  mysql_errno(): supplied argument is not a valid MySQL-Link resource in .../Sources/Subs-Db-mysql.php on line 415


// This is the error message...
     $query_error = mysql_error($connection);     $query_errno = mysql_errno($connection);





[15-Apr-2012 18:59:18] PHP Warning:  mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in .../Sources/Subs-Db-mysql.php on line 368

     // Debugging.
     if (isset($db_show_debug) && $db_show_debug === true)
         $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));

     return $ret;
}

function smf_db_affected_rows($connection = null)
{
     global $db_connection;

     return mysql_affected_rows($connection == null ? $db_connection : $connection); }

function smf_db_insert_id($table, $field = null, $connection = null)
{
     global $db_connection, $db_prefix;

     $table = str_replace('{db_prefix}', $db_prefix, $table);

     // MySQL doesn't need the table or field information.
     return mysql_insert_id($connection == null ? $db_connection : $connection);
}



seems they stay away until something is deemed not right then they create again and again. My host says they have looked over everything totally and all is set fine that perhaps SMF has a very well hidden bug somewhere for this to be happening...yet no explaination from anyone as to why only the one forum on our VPS and not the others that are exactly alike.[/color]
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

Arantor

Again, as I pointed out months ago, it is not a hidden bug in SMF. It is a situation that is not meant to happen (in fact, it's a situation that only ever happens when older versions of MySQL are put under intense load) and one that SMF, nor any other forum package for that matter, is expected to deal with.

The change I indicated would deal with it, or at least what can be dealt with at the SMF level, because it's not something SMF should have to deal with.

For those who didn't bother to read back earlier in the thread, let me explain.

SMF issues a query to the database in the event of an error, so it can be logged and dealt with. That's fine, until the error is that the connection to the database has been lost. At which time it tries to log it, only to find that it doesn't have a database connection and throws another error, ad infinitum.

The test I suggested copes with the case of checking that the connection is still valid before logging, and failing safely if not. SMF should NOT attempt to reconnect during that thread if connection is lost, it will make things worse if it does (if the connection was lost, it was lost because the thread was terminated from outside and making more threads will make it worse, not better)
Holder of controversial views, all of which my own.


MrPhil

Does this: http://www.simplemachines.org/community/index.php?topic=471886.msg3316588#msg3316588 shed any light on the subject? It looks to me that there are certain error handling paths that leave the global default connection as boolean 'false' instead of some valid resource (or null). Something to be looked at...

Arantor

Not really, no.

If mysql_(p)connect fails, you get dumped straight at the Connection Problems screen up front, and nothing more. What's happening is that the initial connect is succeeding, so normal page generation begins but at some point after that the connection is dropped, and once that happens you're screwed unless it happens sufficiently late in the process that all normal DB calls happen.

Remember, $db_connection is a Resource. That means all the time the mysql binding (note lower case) has a connection, it's not false but if the connection drops for any reason that Resource will be unset automatically. Normally it's only a case when the thread is closed for any reason, and what I'm seeing is that certain versions of MySQL dropped connections as well as certain hosts setting watchdogs to kill any 'long running' connections.
Holder of controversial views, all of which my own.


DarkAngel612

I thought that maybe it might have been associated with c-panel newest version. They have a bug they are chasing that affect some things.

What can I do to stop the error from myltiplying and taking over thus creating a huge file...be kind am learning php
Fantasy Attic ::  Fantasies Realm Market :: SMF 2.1.4 with various mods and TinyPortal

Arantor

Read the whole of this thread, I documented a change to Subs-Db-Mysql.php that will end execution safely rather than throw a lot of errors into the log.
Holder of controversial views, all of which my own.


Advertisement: