Summary: Query a MySQL database server and display the results in a wiki page
Version: 2019-01-26
Categories: Integration, Data, PHP55, PHP72
Discussion: MyPmWiki-Talk


Query a MySQL database server and display the results in a wiki page.


A module called MyPmWiki that allows you to use SQL statements in a wiki page to query a MySQL database and display the results with a table.


Add this script to your "local" directory:


Include it in local.php with:


Set these variables in local.php:

hostname of the MySQL server (default is "localhost")
username to access the MySQL server (see caution below)
password to access the MySQL server (see caution below)
name of the database to use
formatting for the table tag (default is "border='1'")

The first and last variables are optional. All others must be set for MyPmWiki to work.

Caution: Unless you want to allow anyone to modify your database, make sure that you set up a user for MyPmWiki that has ONLY select privileges. Also, you must include the unencrypted password for this user in your local.php file. This user should have very limited rights to your MySQL server.


(:MyPmWiki SQL statement:)


 (:MyPmWiki SELECT COUNT(*) as Number FROM devtable WHERE ACTION LIKE LOWER('%ipp%'):)

Working example:


  • 2005-09-28
    • changed Markup from _begin to inline
  • 2016-10-21
    • update for PHP 5.5 compatibility
    • * 2019-01-26
    • update for PHP 7.2 compatibility

See also:

I've just contributed two new recipes that IMHO are safer and more functional than this one: SelectQuery and UpdateForm. Ben Stallings


JamesDavis, fraz, Mike, Siegfried Seibert


See discussion at MyPmWiki-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.