From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png

Release status:Extension status beta

ImplementationTemplate:Extension#type Tag
DescriptionTemplate:Extension#description Run a custom query on an external database.
Author(s)Template:Extension#username freakolowsky (old code by Patrick Müller)
Latest versionTemplate:Extension#version 1.0 (30.05.11)
MediaWikiTemplate:Extension#mediawiki Works with 1.17
LicenseTemplate:Extension#license No license specified

Translate the SQL2Wiki extension if it is available at translatewiki.net

Check usage and version matrix.

Warning Warning: This extension IS EXTREMELY DANGEROUS as it enables as it gives a user direct access to the database. USE EXTREME CAUTION when enabling this extension. User permissions must be handled on the database level. In most cases the connections to external databases should be read-only on table level.

What can this extension do?[edit]

This is a remake of an old extension that has been untouched for a while now, the old extension page has been copied to Extension:SQL2Wiki/old

This extension can run a custom query on an external database (not the database MW is running on). For databases supporting PLSQL (currently only supported for Oracle) this extension can also provide execution of an PLSQL anonymous block. Extension uses direct SQL calls so the queries have to be in the correct format for desired database.


  1. Download the files from SVN and place them in $IP/extensions/SQL2Wiki/ (It is now available here).
  2. Add
    into your wiki's LocalSettings.php
  3. Specify databases you want to access into
    $wgExSql2WikiDatabases["db1"] = array( "type"=> "oracle", "host" => "tnsname", "dbname" => "scott", "user" => "scott", "password" => "tiger");
    in your wiki's LocalSettings.php

Usage examples[edit]

  • Show data in a table

<sql2wiki database="db1"> select * from dual </sql2wiki>

  • Show data inline

<sql2wiki database="db1" inline="span"> select * from dual </sql2wiki>

    • if there is more than one column or row in the target table the data will be separated with line/field separator characters that can be defined as tag parameters
  • Execute PLSQL anonymous block (output can be returned trough DBMS_OUTPUT system)

<plsql2wiki database="db1"> BEGIN dbms_output.put_line('result!!'); END; </plsql2wiki>


  • General parameters:
    • database = Database id (array key in $wgExSql2WikiDatabases array) (required)
    • inline = inline tag to wrap the results into. If this parameter is omitted the result will be displayed as table in case of sql2wiki or span tag in case of plsql2wiki
    • quiet = in case of error display nothing (true|false)
    • preexpand = recursive parse of input text before executing query (true|false)
    • expand = recursive parse of query result (true|false)
    • cache = handle page caching. In case of plsql or table display setting this parameter to "manual" will cause a refresh link to be placed under the displayed data (on|off|manual)
  • Inline parameters:
    • fieldseparator = character that separates fields in inline display (not displayed after last field)
    • lineseparator = character that separates rows in inline display (by default newlines are appended on rows)
  • Table parameters:
    • noheader = omit table header row (by default filled with column names) (true|false)
    • (table|hrow|hcell|row|cell)style = style attribute applied to table, header row, header cell, data row or data cell.

All other parameters passed to the tag will be appended to attributes of inline or table tag on output.


1.0 - Remake release - 30.05.11 (the old extension page has been copied to Extension:SQL2Wiki/old)