<?php
-include_once( "FulltextStoplist.php" );
-include_once( "CacheManager.php" );
+# $Id$
+# This file deals with MySQL interface functions
+# and query specifics/optimisations
+#
+require_once( "CacheManager.php" );
define( "DB_READ", -1 );
define( "DB_WRITE", -2 );
}
if ( false === $ret ) {
+ $error = mysql_error( $this->mConn );
+ $errno = mysql_errno( $this->mConn );
if( $this->mIgnoreErrors ) {
- wfDebug("SQL ERROR (ignored): " . mysql_error( $this->mConn ) . "\n");
+ wfDebug("SQL ERROR (ignored): " . $error . "\n");
} else {
- wfDebug("SQL ERROR: " . mysql_error( $this->mConn ) . "\n");
+ wfDebug("SQL ERROR: " . $error . "\n");
if ( $this->mOut ) {
// this calls wfAbruptExit()
- $this->mOut->databaseError( $fname, $this );
+ $this->mOut->databaseError( $fname, $sql, $error, $errno );
}
}
}
}
return $row;
}
+
+ function fetchRow( $res ) {
+ @$row = mysql_fetch_array( $res );
+ if (mysql_errno() ) {
+ wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( mysql_error() ) );
+ }
+ return $row;
+ }
+
function numRows( $res ) {
@$n = mysql_num_rows( $res );
if( mysql_errno() ) {
# If errors are explicitly ignored, returns NULL on failure
function indexExists( $table, $index, $fname = "Database::indexExists" )
{
- $sql = "SHOW INDEXES FROM $table";
+ # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
+ # SHOW INDEX should work for 3.x and up:
+ # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
+ $sql = "SHOW INDEX FROM $table";
$res = $this->query( $sql, DB_READ, $fname );
if ( !$res ) {
return NULL;
function tableExists( $table )
{
$old = $this->mIgnoreErrors;
+ $this->mIgnoreErrors = true;
$res = $this->query( "SELECT 1 FROM $table LIMIT 1" );
$this->mIgnoreErrors = $old;
if( $res ) {
"9876543210"
);
}
+
+function wfLimitResult( $limit, $offset ) {
+ return " LIMIT ".(is_numeric($offset)?"{$offset},":"")."{$limit} ";
+}
+
?>