DatabaseMysql Class Reference
[Database]

Database abstraction object for mySQL Inherit all methods and properties of Database::Database(). More...

Inherits DatabaseBase.

Inherited by Database.

List of all members.

Public Member Functions

 getType ()
 Get the type of the DBMS, as it appears in $wgDBtype.
 doQuery ($sql)
 The DBMS-dependent part of query().
 open ($server, $user, $password, $dbName)
 Usually aborts on failure If the failFunction is set to a non-zero integer, returns success.
 close ()
 Closes a database connection.
 freeResult ($res)
 Free a result object.
 fetchObject ($res)
 Fetch the next row from the given result object, in object form.
 fetchRow ($res)
 Fetch the next row from the given result object, in associative array form.
 numRows ($res)
 Get the number of rows in a result object.
 numFields ($res)
 Get the number of fields in a result object See documentation for mysql_num_fields().
 fieldName ($res, $n)
 Get a field name in a result object See documentation for mysql_field_name(): http://www.php.net/mysql_field_name.
 insertId ()
 Get the inserted value of an auto-increment row.
 dataSeek ($res, $row)
 Change the position of the cursor in a result object See mysql_data_seek().
 lastErrno ()
 Get the last error number See mysql_errno().
 lastError ()
 Get a description of the last error See mysql_error() for more details.
 affectedRows ()
 Get the number of rows affected by the last write query See mysql_affected_rows() for more details.
 estimateRowCount ($table, $vars='*', $conds='', $fname= 'Database::estimateRowCount', $options=array())
 Estimate rows in dataset Returns estimated count, based on EXPLAIN output Takes same arguments as Database::select().
 fieldInfo ($table, $field)
 mysql_fetch_field() wrapper Returns false if the field doesn't exist
 selectDB ($db)
 Change the current database.
 strencode ($s)
 Wrapper for addslashes().
 ping ()
 Ping the server and try to reconnect if it there is no connection.
 getServerVersion ()
 A string describing the current software version, like from mysql_get_server_info().
 useIndexClause ($index)
 USE INDEX clause.
 lowPriorityOption ()
 A string to insert into queries to show that they're low-priority, like MySQL's LOW_PRIORITY.
 getSoftwareLink ()
 Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at least contain plain text, if for some reason your database has no website.
 standardSelectDistinct ()
 Returns true if this database requires that SELECT DISTINCT queries require that all ORDER BY expressions occur in the SELECT list per the SQL92 standard.
 setTimeout ($timeout)
 Override database's default connection timeout.
 lock ($lockName, $method, $timeout=5)
 Acquire a named lock.
 unlock ($lockName, $method)
 Release a lock.
 lockTables ($read, $write, $method, $lowPriority=true)
 Lock specific tables.
 unlockTables ($method)
 Unlock specific tables.
 setBigSelects ($value=true)
 Allow or deny "big selects" for this session only.
 wasDeadlock ()
 Determines if the last failure was due to a deadlock.
 wasErrorReissuable ()
 Determines if the last query error was something that should be dealt with by pinging the connection and reissuing the query.
 wasReadOnlyError ()
 Determines if the last failure was due to the database being read-only.
 duplicateTableStructure ($oldName, $newName, $temporary=false, $fname= 'DatabaseMysql::duplicateTableStructure')
 Creates a new table with structure copied from existing table Note that unlike most database abstraction functions, this function does not automatically append database prefix, because it works at a lower abstraction level.


Detailed Description

Database abstraction object for mySQL Inherit all methods and properties of Database::Database().

See also:
Database

Definition at line 9 of file DatabaseMysql.php.


Member Function Documentation

DatabaseMysql::affectedRows (  ) 

Get the number of rows affected by the last write query See mysql_affected_rows() for more details.

Reimplemented from DatabaseBase.

Definition at line 235 of file DatabaseMysql.php.

DatabaseMysql::close (  ) 

Closes a database connection.

if it is open : commits any open transactions

Returns:
Bool operation success. true if already closed.

Reimplemented from DatabaseBase.

Definition at line 132 of file DatabaseMysql.php.

References DatabaseBase::commit(), and DatabaseBase::trxLevel().

Referenced by open().

DatabaseMysql::dataSeek ( res,
row 
)

Change the position of the cursor in a result object See mysql_data_seek().

Parameters:
$res Mixed: A SQL result
$row Mixed: Either MySQL row or ResultWrapper

Reimplemented from DatabaseBase.

Definition at line 202 of file DatabaseMysql.php.

References $res.

DatabaseMysql::doQuery ( sql  ) 

The DBMS-dependent part of query().

Parameters:
$sql String: SQL query.
Returns:
Result object to feed to fetchObject, fetchRow, ...; or false on failure

Reimplemented from DatabaseBase.

Definition at line 14 of file DatabaseMysql.php.

References DatabaseBase::bufferResults().

DatabaseMysql::duplicateTableStructure ( oldName,
newName,
temporary = false,
fname = 'DatabaseMysql::duplicateTableStructure' 
)

Creates a new table with structure copied from existing table Note that unlike most database abstraction functions, this function does not automatically append database prefix, because it works at a lower abstraction level.

Parameters:
$oldName String: name of table whose structure should be copied
$newName String: name of table to be created
$temporary Boolean: whether the new table should be temporary
Returns:
Boolean: true if operation was successful

Reimplemented from DatabaseBase.

Definition at line 409 of file DatabaseMysql.php.

References $fname, $res, fetchRow(), getServerVersion(), and DatabaseBase::query().

DatabaseMysql::estimateRowCount ( table,
vars = '*',
conds = '',
fname = 'Database::estimateRowCount',
options = array() 
)

Estimate rows in dataset Returns estimated count, based on EXPLAIN output Takes same arguments as Database::select().

Reimplemented from DatabaseBase.

Definition at line 242 of file DatabaseMysql.php.

References $fname, $options, $res, $rows, fetchObject(), freeResult(), numRows(), and DatabaseBase::select().

DatabaseMysql::fetchObject ( res  ) 

Fetch the next row from the given result object, in object form.

Fields can be retrieved with $row->fieldname, with fields acting like member variables.

Parameters:
$res SQL result object as returned from Database::query(), etc.
Returns:
MySQL row object
Exceptions:
DBUnexpectedError Thrown if the database returns an error

Reimplemented from DatabaseBase.

Definition at line 153 of file DatabaseMysql.php.

References $res, lastErrno(), and lastError().

Referenced by estimateRowCount(), lock(), and unlock().

DatabaseMysql::fetchRow ( res  ) 

Fetch the next row from the given result object, in associative array form.

Fields are retrieved with $row['fieldname'].

Parameters:
$res SQL result object as returned from Database::query(), etc.
Returns:
MySQL row object
Exceptions:
DBUnexpectedError Thrown if the database returns an error

Reimplemented from DatabaseBase.

Definition at line 164 of file DatabaseMysql.php.

References $res, lastErrno(), and lastError().

Referenced by duplicateTableStructure().

DatabaseMysql::fieldInfo ( table,
field 
)

mysql_fetch_field() wrapper Returns false if the field doesn't exist

Parameters:
$table 
$field 

Reimplemented from DatabaseBase.

Definition at line 261 of file DatabaseMysql.php.

References $i, $n, $res, DatabaseBase::query(), and DatabaseBase::tableName().

DatabaseMysql::fieldName ( res,
n 
)

Get a field name in a result object See documentation for mysql_field_name(): http://www.php.net/mysql_field_name.

Parameters:
$res Mixed: A SQL result
$n Integer

Reimplemented from DatabaseBase.

Definition at line 193 of file DatabaseMysql.php.

References $n, and $res.

DatabaseMysql::freeResult ( res  ) 

Free a result object.

Parameters:
$res Mixed: A SQL result

Reimplemented from DatabaseBase.

Definition at line 144 of file DatabaseMysql.php.

References $res.

Referenced by estimateRowCount(), and lock().

DatabaseMysql::getServerVersion (  ) 

A string describing the current software version, like from mysql_get_server_info().

Will be listed on Special:Version, etc.

Returns:
String: Version information from the database

Reimplemented from DatabaseBase.

Definition at line 304 of file DatabaseMysql.php.

Referenced by duplicateTableStructure(), and open().

DatabaseMysql::getSoftwareLink (  ) 

Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at least contain plain text, if for some reason your database has no website.

Returns:
String: wikitext of a link to the server software's web site

Reimplemented from DatabaseBase.

Definition at line 316 of file DatabaseMysql.php.

DatabaseMysql::getType (  ) 

Get the type of the DBMS, as it appears in $wgDBtype.

Reimplemented from DatabaseBase.

Definition at line 10 of file DatabaseMysql.php.

DatabaseMysql::insertId (  ) 

Get the inserted value of an auto-increment row.

The value inserted should be fetched from nextSequenceValue()

Example: $id = $dbw->nextSequenceValue('page_page_id_seq'); $dbw->insert('page',array('page_id' => $id)); $id = $dbw->insertId();

Reimplemented from DatabaseBase.

Definition at line 200 of file DatabaseMysql.php.

DatabaseMysql::lastErrno (  ) 

Get the last error number See mysql_errno().

Reimplemented from DatabaseBase.

Definition at line 209 of file DatabaseMysql.php.

Referenced by fetchObject(), fetchRow(), numRows(), wasDeadlock(), wasErrorReissuable(), and wasReadOnlyError().

DatabaseMysql::lastError (  ) 

Get a description of the last error See mysql_error() for more details.

Reimplemented from DatabaseBase.

Definition at line 217 of file DatabaseMysql.php.

References wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by fetchObject(), fetchRow(), numRows(), open(), and wasReadOnlyError().

DatabaseMysql::lock ( lockName,
method,
timeout = 5 
)

Acquire a named lock.

Abstracted from Filestore::lock() so child classes can implement for their own needs.

Parameters:
$lockName String: Name of lock to aquire
$method String: Name of method calling us
Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 329 of file DatabaseMysql.php.

References $result, DatabaseBase::addQuotes(), fetchObject(), freeResult(), DatabaseBase::query(), and wfDebug().

DatabaseMysql::lockTables ( read,
write,
method,
lowPriority = true 
)

Lock specific tables.

Parameters:
$read Array of tables to lock for read access
$write Array of tables to lock for write access
$method String name of caller
$lowPriority bool Whether to indicate writes to be LOW PRIORITY

Reimplemented from DatabaseBase.

Definition at line 350 of file DatabaseMysql.php.

References DatabaseBase::query(), and DatabaseBase::tableName().

DatabaseMysql::lowPriorityOption (  ) 

A string to insert into queries to show that they're low-priority, like MySQL's LOW_PRIORITY.

If no such feature exists, return an empty string and nothing bad should happen.

Returns:
string Returns the text of the low priority option if it is supported, or a blank string otherwise

Reimplemented from DatabaseBase.

Definition at line 312 of file DatabaseMysql.php.

DatabaseMysql::numFields ( res  ) 

Get the number of fields in a result object See documentation for mysql_num_fields().

Parameters:
$res Mixed: A SQL result

Reimplemented from DatabaseBase.

Definition at line 186 of file DatabaseMysql.php.

References $res.

DatabaseMysql::numRows ( res  ) 

Get the number of rows in a result object.

Parameters:
$res Mixed: A SQL result

Reimplemented from DatabaseBase.

Definition at line 175 of file DatabaseMysql.php.

References $n, $res, lastErrno(), and lastError().

Referenced by estimateRowCount().

DatabaseMysql::open ( server,
user,
password,
dbName 
)

Usually aborts on failure If the failFunction is set to a non-zero integer, returns success.

Parameters:
$server String: database server host
$user String: database user name
$password String: database user password
$dbName String: database name

Reimplemented from DatabaseBase.

Definition at line 23 of file DatabaseMysql.php.

References $i, $success, $version, $wgAllDBsAreLocalhost, $wgDBmysql5, close(), getServerVersion(), DatabaseBase::installErrorHandler(), lastError(), DatabaseBase::query(), DatabaseBase::reportConnectionError(), DatabaseBase::restoreErrorHandler(), wfDebug(), wfHostname(), wfLogDBError(), wfProfileIn(), and wfProfileOut().

Referenced by ping().

DatabaseMysql::ping (  ) 

Ping the server and try to reconnect if it there is no connection.

Returns:
bool Success or failure

Reimplemented from DatabaseBase.

Definition at line 283 of file DatabaseMysql.php.

References open(), and wfDebug().

DatabaseMysql::selectDB ( db  ) 

Change the current database.

Returns:
bool Success or failure

Reimplemented from DatabaseBase.

Definition at line 274 of file DatabaseMysql.php.

DatabaseMysql::setBigSelects ( value = true  ) 

Allow or deny "big selects" for this session only.

This is done by setting the sql_big_selects session variable.

This is a MySQL-specific feature.

Parameters:
mixed $value true for allow, false for deny, or "default" to restore the initial value

Reimplemented from DatabaseBase.

Definition at line 370 of file DatabaseMysql.php.

References DatabaseBase::query(), and DatabaseBase::selectField().

DatabaseMysql::setTimeout ( timeout  ) 

Override database's default connection timeout.

May be useful for very long batch queries such as full-wiki dumps, where a single query reads out over hours or days. May or may not be necessary for non-MySQL databases. For most purposes, leaving it as a no-op should be fine.

Parameters:
$timeout Integer in seconds

Reimplemented from DatabaseBase.

Definition at line 324 of file DatabaseMysql.php.

References DatabaseBase::query().

DatabaseMysql::standardSelectDistinct (  ) 

Returns true if this database requires that SELECT DISTINCT queries require that all ORDER BY expressions occur in the SELECT list per the SQL92 standard.

Reimplemented from DatabaseBase.

Definition at line 320 of file DatabaseMysql.php.

DatabaseMysql::strencode ( s  ) 

Wrapper for addslashes().

Parameters:
$s String: to be slashed.
Returns:
String: slashed string.

Reimplemented from DatabaseBase.

Definition at line 279 of file DatabaseMysql.php.

References $s.

DatabaseMysql::unlock ( lockName,
method 
)

Release a lock.

Parameters:
$lockName String: Name of lock to release
$method String: Name of method calling us
FROM MYSQL DOCS: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock
Returns:
Returns 1 if the lock was released, 0 if the lock was not established by this thread (in which case the lock is not released), and NULL if the named lock did not exist

Reimplemented from DatabaseBase.

Definition at line 343 of file DatabaseMysql.php.

References $result, DatabaseBase::addQuotes(), fetchObject(), and DatabaseBase::query().

DatabaseMysql::unlockTables ( method  ) 

Unlock specific tables.

Parameters:
$method String the caller

Reimplemented from DatabaseBase.

Definition at line 366 of file DatabaseMysql.php.

References DatabaseBase::query().

DatabaseMysql::useIndexClause ( index  ) 

USE INDEX clause.

Unlikely to be useful for anything but MySQL. This is only needed because a) MySQL must be as efficient as possible due to its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about which index to pick. Anyway, other databases might have different indexes on a given table. So don't bother overriding this unless you're MySQL.

Reimplemented from DatabaseBase.

Definition at line 308 of file DatabaseMysql.php.

References DatabaseBase::indexName().

DatabaseMysql::wasDeadlock (  ) 

Determines if the last failure was due to a deadlock.

Reimplemented from DatabaseBase.

Definition at line 389 of file DatabaseMysql.php.

References lastErrno().

DatabaseMysql::wasErrorReissuable (  ) 

Determines if the last query error was something that should be dealt with by pinging the connection and reissuing the query.

Reimplemented from DatabaseBase.

Definition at line 397 of file DatabaseMysql.php.

References lastErrno().

DatabaseMysql::wasReadOnlyError (  ) 

Determines if the last failure was due to the database being read-only.

Reimplemented from DatabaseBase.

Definition at line 404 of file DatabaseMysql.php.

References lastErrno(), and lastError().


The documentation for this class was generated from the following file:

Generated on Sat Apr 30 22:57:35 2011 for MediaWiki by  doxygen 1.5.9