Loading...
 
Skip to main content

History: Admin DSN

Source of version: 15 (current)

Copy to clipboard
            !Admin DSN

^The Admin DSN page also contains content authentication settings. See ((Content Authentication)) for more information about that^

Have you ever wished you could retrieve data that is actually in TikiWiki's (or some other) database, but not organized or displayed on-screen in the way you'd like?  The SQL plugin can be used to display the results of SELECT queries in a Wiki page.  The plugin displays the results of the query in an attractively formatted table.  

To use the SQL plugin, you must do the following:
# Use __Admin DSN__ to define the database to be used by the SQL plugin.  
# Place a SQL plugin statement in a Wiki page.  Please see ((PluginSQL)) for instructions.

This page page shows you how to define a DSN so that the SQL plugin can access external data. 

-=Notes=-
This documentation was originaly based on Tikiwiki 1.7.5 but has been succesfully used for TikiWiki 2.2.

!! Usage
!!! How to Define a DSN
1. On the main Tiki menu, click Admin (if necessary to show the options below this menu item).
1.a. Under the Admin menu in some versions of tikiwiki you can click a link to "Admin DSN" ( -+tiki-admin_dsn.php+- ) to go there directly. 
1.b. In more recent versions (works in 2.2) you should click "Admin Home". At the bottom of the Admin Home page you will see "More Links" and in the Text area features area click the link to "DSN".

2. You'll see the Admin DSN page, shown here: 
{THUMB(image=>img/wiki_up/admin-dsn.jpg,max=>600)}{THUMB} 

3. In the Name area, type a name for the external database you want to use.  The name cannot contain spaces.  

4. In the DSN area, type a valid DSN.  See "DSN Syntax," below.

5. Click Save.

!!! DSN Syntax

To define the DSN, you need to specify:
*__Database Type__ If you are using MySQL, the database type is ''mysql''. If you are using Postgresql, the database type is "pgsql".
*__User__  Supply the name of the user that is qualified to access the database server.
*__Password__ Supply the password for the qualified user.
*__Database name__ Supply the name of the database that contains the desired data.

Here's the syntax:

{CODE(ln=>1,colors=>php)}DSN format: database-type://user:password@host/database-name{CODE}

!!! Tutorial

In this example we are creating a DSN for the database ''tiki'' in host ''localhost'' using the user ''root'' and the password ''seldon''.  The DSN will be named ''cosa'' (as in "Cosa Nostra").   

Here's how the DSN looks:

{CODE(ln=>1,colors=>php)}mysql://root:seldon@localhost/tiki{CODE}

!!! Permissions

When a DSN is created with name ''foo'' the permission tiki_p_dsn_''foo'' is automatically created. Only users with that permission can use the DSN to create a query or view the results of a query using that DSN.  For more information on the permissions aspect of the SQL plugin, see ((PluginSQL)). 

In older versions of tikiwiki this permission needed to be added manually in the users_permissions table and the following syntax was suggested:
{CODE()}
INSERT INTO users_permissions (permName, permDesc, level, type, admin) VALUES ('tiki_p_dsn_localhost', 'Can query localhost', 'dsn', '', '');
{CODE}
It should not be needed in more recent versions (certainly 2.2 and above) but if you do need to add the permission manually consider using the following, which also sets the permission type:
{CODE()}
INSERT INTO users_permissions (permName, permDesc, level, type, admin) VALUES ('tiki_p_dsn_localhost', 'Can query localhost', 'dsn', 'dsn', '');
{CODE}

-=For more information=-
See ((PluginSQL)) to learn how to insert SQL queries in Wiki pages.