Hi,
I used to do: $db =& wfGetDB(DB_SLAVE); $tbl = $db->tableName('interwiki');
$result = $db->query("SELECT iw_prefix,iw_url,iw_local,iw_trans FROM $tbl");
while ( $row = mysql_fetch_array($result) ) $this->iwl[ $row[0] ] = array( 'uri' => $row[1], 'local' => $row[2], 'trans' => $row[3] ); $db->freeResult( $result );
in MW1.10 but now it seems this code does not work under MW1.11.
Help please, Jean-Lou Dupont.
Jean-Lou Dupont wrote:
I used to do: $db =& wfGetDB(DB_SLAVE); $tbl = $db->tableName('interwiki');
$result = $db->query("SELECT iw_prefix,iw_url,iw_local,iw_trans
FROM $tbl");
while ( $row = mysql_fetch_array($result) ) $this->iwl[ $row[0] ] = array( 'uri' => $row[1], 'local' =>
$row[2], 'trans' => $row[3] ); $db->freeResult( $result );
in MW1.10 but now it seems this code does not work under MW1.11.
You're mixing abstraction levels, which leads to breakage when the implementation changes.
mysql_fetch_array() requires a MySQL result resources as its parameter, but $db->query() is not guaranteed to return one.
In recent versions of MediaWiki it returns a ResultWrapper instance, which can be queried or iterated over as well as passed back to the Database instance.
You can use $db->fetchRow( $result ) for better compatibility. (Most MediaWiki code uses fetchObject() instead, but it doesn't really matter which as long as you know what you're using.)
-- brion vibber (brion @ wikimedia.org)
Thank you very much Mr. Vibber.
I'll be more careful with the code I nick next time.
Cheers, Jean-Lou Dupont.
On 10/9/07, Brion Vibber brion@wikimedia.org wrote:
Jean-Lou Dupont wrote:
I used to do: $db =& wfGetDB(DB_SLAVE); $tbl = $db->tableName('interwiki');
$result = $db->query("SELECT iw_prefix,iw_url,iw_local,iw_trans
FROM $tbl");
while ( $row = mysql_fetch_array($result) ) $this->iwl[ $row[0] ] = array( 'uri' => $row[1], 'local' =>
$row[2], 'trans' => $row[3] ); $db->freeResult( $result );
in MW1.10 but now it seems this code does not work under MW1.11.
You're mixing abstraction levels, which leads to breakage when the implementation changes.
mysql_fetch_array() requires a MySQL result resources as its parameter, but $db->query() is not guaranteed to return one.
In recent versions of MediaWiki it returns a ResultWrapper instance, which can be queried or iterated over as well as passed back to the Database instance.
You can use $db->fetchRow( $result ) for better compatibility. (Most MediaWiki code uses fetchObject() instead, but it doesn't really matter which as long as you know what you're using.)
-- brion vibber (brion @ wikimedia.org)
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org