Last modified: 2011-08-25 16:59:53 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T29667, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 27667 - mysql_real_escape_string() expects parameter 2 to be resource, null
mysql_real_escape_string() expects parameter 2 to be resource, null
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Database (Other open bugs)
1.18.x
All All
: Normal critical (vote)
: ---
Assigned To: Nobody - You can work on this!
http://biowikifarm.net/test/Template:...
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-02-23 21:03 UTC by Gregor Hagedorn
Modified: 2011-08-25 16:59 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Gregor Hagedorn 2011-02-23 21:03:52 UTC
With version r82697 (http://biowikifarm.net/test/Special:Version )
(as well as with a versions a number of days back, the error is a few days old), the following error occurs:

Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /usr/share/mediawikistaging/phase3/includes/db/DatabaseMysql.php on line 316

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /usr/share/mediawikistaging/phase3/includes/db/DatabaseMysql.php on line 23
Database error

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was:
BEGIN
from within function "DatabaseBase::begin". Database returned error "0: ".

I have tried to test a possible dependency on additional extensions, but disabling extensions does not help (with the exception of ParserFunctions, which disables much of the template processing, so it is probably unrelated). Disabling SMW does not remove the error.

Gregor
Comment 1 Sam Reed (reedy) 2011-02-23 22:04:34 UTC
It looks to be something with the templates you're using... I can't seem to reproduce it (And I'd rather not have to try and duplicate your whole wiki...)

It seems to be on your templates with multiple parser function calls etc...
Comment 2 Gregor Hagedorn 2011-02-23 22:21:27 UTC
It occurs only on specific pages - but the templates in question are inherited from en.wikipedia...

There is a second page which produces funny results, but this occurs in the context of SMW (the error above occurs with SMW disabled as well).

http://biowikifarm.net/test/Special:FormEdit/Artportrait/Bombus

Any of the errors point to code lines that have recently been modified?
(Version r79596 did not have this error yet).
Comment 3 Sam Reed (reedy) 2011-02-23 22:23:49 UTC
That could is unlikely to tell us, we really need a call stack


And now, the errors seem to be gone on your wiki now...
Comment 4 Sam Reed (reedy) 2011-02-23 22:24:17 UTC
*On some pages
Comment 5 Sam Reed (reedy) 2011-02-23 22:26:44 UTC
	function strencode( $s ) {
		try
		{
			$sQuoted = mysql_real_escape_string( $s, $this->mConn );

			if($sQuoted === false) {
				$this->ping();
				$sQuoted = mysql_real_escape_string( $s, $this->mConn );
			}
			return $sQuoted;
		} catch (Exception $e) {
			var_dump($e);
			var_dump(debug_backtrace());
			return $s;
		}
	}

Replace the existing function with something like that. At least we'll get some idea of where it's failing
Comment 6 Gregor Hagedorn 2011-02-23 22:42:14 UTC
Apologies for removing the error temporarily, I was trying to pinpoint which templates may cause it, to simplify the solution. Failed however. Error is back. 

Function is replaced as requested above.

wgShowDebug is true now.


Please remind me how I get the call stack. I did it months ago, but can't remember. Link to instructions?
Comment 7 Sam Reed (reedy) 2011-02-23 22:43:40 UTC
If you go to includes/db/DatabaseMySql.php, and replace the strencode function with the one pasted above, that should give some insight
Comment 8 Gregor Hagedorn 2011-02-23 22:50:36 UTC
I did replace the function as mentioned above. I see not change. Sorry, I am not very experienced with debugging. Settings are:


$wgShowSQLErrors = true;
$wgShowDebug        = true;// if true debug data shown on the wiki page at the bottom
$wgShowExceptionDetails = true; 
error_reporting(E_ALL);
ini_set("display_errors", 1);
$wgDebugLogFile = "$IP/debug.log";
Comment 9 Chad H. 2011-05-29 23:00:11 UTC
(In reply to comment #5)
>   [snip]
> Replace the existing function with something like that. At least we'll get some
> idea of where it's failing

Why would a try/catch block catch an E_WARNING?
Comment 10 Pablo Castellano (IRC: pablog) 2011-07-03 00:36:47 UTC
I have this same issue.

I was using mediawiki 1.16.2 and I have upgraded it to 1.17.0, having upgraded the sql schemas. Everything seems to work fine except my user wikipage that shows these errors.
Comment 11 Till Kraemer 2011-08-15 13:22:21 UTC
Just upgraded from 1.16 to 1.17 and I'm getting the same error when I set  $wgUseSharedUploads = true; (I'm running four interwikis sharing one pool wiki for the media files). Would be nice though, if my wikis had images again :|

Here is the output:

Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /html/wiki/en/w/includes/db/DatabaseMysql.php on line 318

Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /html/wiki/en/w/includes/db/DatabaseMysql.php on line 318

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /html/wiki/en/w/includes/db/DatabaseMysql.php on line 23

A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was: 
BEGIN
from within function "DatabaseBase::begin". Database returned error "0: ". 

Debug data:
Start request 
   
GET /wiki/Main_Page 
HTTP HEADERS: 
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 
Accept-Encoding: gzip, deflate 
Accept-Language: en,de;q=0.9,de-DE;q=0.8 
Cache-Control: no-cache 
Connection: Keep-Alive 
Cookie: database_3UserID=1; database_3UserName=Till+Kraemer; database_3Token=1d8916427743c36ef3936c5f20a8c9e3; awc_startTime=20110814185359; database_3_session=2bauhg71ti53lp57pfhqage6q2; __utma=162725736.456536178.1297683604.1313346115.1313410956.169; __utmb=162725736.37.10.1313410956; __utmc=162725736; __utmz=162725736.1313410956.169.53.utmcsr=pool.domain.com|utmccn=(referral)|utmcmd=referral|utmcct=/wiki/Main_Page 
Host: en.domain.com 
Referer: http://en.domain.com/wiki/Till_Kraemer 
User-Agent: Opera/9.80 (Windows NT 6.1; U; en) Presto/2.9.168 Version/11.50 
   
CACHES: APCBagOStuff[main] APCBagOStuff[message] FakeMemCachedClient[parser] 
Unstubbing $wgParser on call of $wgParser::setFunctionHook from SimpleSecurity::__construct 
Unstubbing $wgOut on call of $wgOut::_unstub from wfDebug 
Unstubbing $wgContLang on call of $wgContLang::getMagic from MagicWord::load 
LocalisationCache: using store LCStore_DB 
Unstubbing $wgMessageCache on call of $wgMessageCache::get from wfMsgGetKey 
Unstubbing $wgLang on call of $wgLang::getCode from MessageCache::get 
User: got user 1 from cache 
Connecting to 111.222.333.444 database_3... 
Connected to 111.222.333.444 database_3. 
User: loading options for user 1 from override cache. 
User: logged in from session 
User: loading options for user 1 from override cache. 
MessageCache::load: Loading en... got from global cache 
Use of MessageCache::addMessages is deprecated. [Called from call_user_func_array in (internal function)] 
Use of MessageCache::addMessage is deprecated. [Called from setupSEOParserHooks in /html/wiki/en/w/extensions/Add_HTML_Meta_and_Title.php at line 57] 
Fully initialised 
Title::getRestrictionTypes: applicable restriction types for Main Page are edit,move,readOutputPage::checkLastModified: CACHE DISABLED 
User::isBlockedFrom: enter 
User::isBlockedFrom: asking isBlocked() 
User::isBlocked: enter 
User::getBlockedStatus: checking... 
IP: 555.666.777.888 
Block::load: '', '1', 1 
Article::view using parser cache: no 
Class SkinMonobook not found; skipped loading 
Article::view: doing uncached parse 
User::isBlockedFrom: enter 
User::isBlockedFrom: asking isBlocked() 
User::isBlocked: enter 
User::getBlockedStatus: already loaded. 
SiteStats::loadAndLazyInit: reading site_stats from slave 
SQL ERROR: 
User::isBlockedFrom: enter 
User::isBlockedFrom: asking isBlocked() 
User::isBlocked: enter 
User::getBlockedStatus: already loaded. 
Title::getRestrictionTypes: applicable restriction types for Main Page are edit,move,read

Any pointers are more thank appreciated!

Thanks + cheers,

Till
Comment 12 Till Kraemer 2011-08-17 05:51:29 UTC
P.S.: Can I just downgrade to 1.16? Or do I have to change the databases somehow?
Comment 13 Gregor Hagedorn 2011-08-25 16:59:53 UTC
Closing the bug. Whatever precisely caused it, has disappeared from code in REL1_18 as well as trunk. The error no longer occurs there.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links