Hi all -
I'm writing an analytics package for MediaWiki and am running into an issue where even though my extension creates a separate mysql connection, MW is catching the DB errors and throwing up its stack trace.
I'm running php 4.4.2 and MW 1.6.3.
It appears that MW is trying to use the mysql connection that my extension has established. a quick look at the MW database.php suggests that this might be an optimization.
Could anyone provide some guidance on how to best avoid this if you are writing an extension that needs to make a mysql connection?
Thanks,
-P-
/** * Peter Adams peter@openwebanalytics.com * * Open Web Analytics - the open source web analytics framework. * Blog >> http://www.openwebanalytics.com/ * Wiki >> http://wiki.openwebanalytics.com */
Peter Adams wrote:
Hi all -
I'm writing an analytics package for MediaWiki and am running into an issue where even though my extension creates a separate mysql connection, MW is catching the DB errors and throwing up its stack trace.
I'm running php 4.4.2 and MW 1.6.3.
It appears that MW is trying to use the mysql connection that my extension has established. a quick look at the MW database.php suggests that this might be an optimization.
Could anyone provide some guidance on how to best avoid this if you are writing an extension that needs to make a mysql connection?
You can create a database connection with new Database(...). This creates a new connection, unless you have DBO_PERSISTENT enabled which you almost certainly don't. Throwing an exception is the standard way to report a query error, if this is a problem for you then you can use $database->ignoreErrors(true). It's probably better though if you just catch the exception, the ignore errors mode isn't very well tested. You can suppress connection errors by passing 1 for the $failFunction parameter of the Database constructor.
-- Tim Starling
thanks for the info Tim. i think I now have a better idea of the what the issue is.
MW is opening a db connection. then my extension is opening a db connection through it's own connection class (not through database.php).
The errors made by the extension's db connection are being caught by MW's database::fetchObject()'s use of mysql_error() which is called without a link identifier. By not calling mysqlerror with a link identifier it is picking up any error found on the last link created (the extension).
Unfortunately, the only way to clear a mysql_error seems to be to run another of php's mysql function (like another query() or mysql_ping ()) or by closing the connection so my catch has to do something pretty inefficient to work around this.
It seems like MW's database::fetchObject function should call mysql_error() with it's own link as the param or at least have an option to do so that could be set by the extension developer. That way extensions that are bridges to large frameworks with their own error handling don't have to worry about MW's error handling or set MW to ignore off all of it's own database errors.
Thoughts/ideas?
-P-
On Jul 14, 2006, at 10:00 PM, Tim Starling wrote:
Peter Adams wrote:
Hi all -
I'm writing an analytics package for MediaWiki and am running into an issue where even though my extension creates a separate mysql connection, MW is catching the DB errors and throwing up its stack trace.
I'm running php 4.4.2 and MW 1.6.3.
It appears that MW is trying to use the mysql connection that my extension has established. a quick look at the MW database.php suggests that this might be an optimization.
Could anyone provide some guidance on how to best avoid this if you are writing an extension that needs to make a mysql connection?
You can create a database connection with new Database(...). This creates a new connection, unless you have DBO_PERSISTENT enabled which you almost certainly don't. Throwing an exception is the standard way to report a query error, if this is a problem for you then you can use $database->ignoreErrors(true). It's probably better though if you just catch the exception, the ignore errors mode isn't very well tested. You can suppress connection errors by passing 1 for the $failFunction parameter of the Database constructor.
-- Tim Starling
Wikitech-l mailing list Wikitech-l@wikimedia.org http://mail.wikipedia.org/mailman/listinfo/wikitech-l
/** * Peter Adams peter@openwebanalytics.com * * Open Web Analytics - the open source web analytics framework. * Blog >> http://www.openwebanalytics.com/ * Wiki >> http://wiki.openwebanalytics.com */
Peter,
Unfortunately, the only way to clear a mysql_error seems to be to run another of php's mysql function (like another query() or mysql_ping ()) or by closing the connection so my catch has to do something pretty inefficient to work around this.
Thanks for reporting this - few direct calls to mysql_error() slipped in lately, I've replaced them with Database::lastErrno() and Database::lastError() which deal with connection contexts properly. Fixed in 15645.
Domas
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Domas Mituzas wrote:
Thanks for reporting this - few direct calls to mysql_error() slipped in lately, I've replaced them with Database::lastErrno() and Database::lastError() which deal with connection contexts properly. Fixed in 15645.
Sounds almost as if it were a wiki. :-)
wikitech-l@lists.wikimedia.org