PHPackages                             rah/rah\_swap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. rah/rah\_swap

ActiveTextpattern-plugin[Database &amp; ORM](/categories/database)

rah/rah\_swap
=============

Swap Textpattern CMS database on the fly

0.2.0(4y ago)222GPL-2.0PHPPHP &gt;=7.1.0CI passing

Since May 6Pushed 10mo ago3 watchersCompare

[ Source](https://github.com/gocom/rah_swap)[ Packagist](https://packagist.org/packages/rah/rah_swap)[ Docs](https://github.com/gocom/rah_swap)[ Fund](https://www.paypal.me/jukkasvahn)[ RSS](/packages/rah-rah-swap/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

rah\_swap
=========

[](#rah_swap)

[Download](https://github.com/gocom/rah_swap/releases) | [Packagist](https://packagist.org/packages/rah/rah_swap) | [Issues](https://github.com/gocom/rah_swap/issues)

Swap connected [Textpattern CMS](https://textpattern.com) MySQL database link on the fly using a template tag. The plugin has the potential to allow pulling templates, articles and other content from different databases.

Install
-------

[](#install)

Using [Composer](https://getcomposer.org):

```
$ composer require rah/rah_swap
```

Or [download](https://github.com/gocom/rah_swap/releases) an installer package.

Basics
------

[](#basics)

```

    ...contained statement...

```

The plugin introduces a new tag, ``. The tag can be used both as a container and as a single, self-closing tag. When used as a container the database connection link is changed for just the wrapped code. The original link is restored on the closing tag pair.

Attributes
----------

[](#attributes)

**db**
Database’s name. If `db` is the only attribute set, currently connected database is changed using current connection’s credentials (user, password, host). A new link isn’t created, but merely the database is swapped reusing the old connection.
Example: `db="myDatabase"` Default: *undefined*

**user**
Username used to connect to the database.
Example: `user="username"` Default: *undefined*

**pass**
User’s password. Can be left empty if the user doesn’t have a password.
Example: `pass="password"` Default: *undefined*

**host**
The database server. The `host` can contain a hostname, a port number or a path to a local socket. Defaults to `localhost`.
Example: `host="hostname.tld:3306"` Default: *undefined*

**dbcharset**
Database’s character set. Usually this attribute should **not** be used, but should be left as it is. Textpattern uses UTF-8, and using non-unicode character set can cause unexpected results.
Example: `dbcharset="latin1"` Default: *undefined*

**client\_flags**
Extra flags passed to the database client. Normally you shouldn’t worry about this attribute. Usually the attribute should **not** be used.
Example: `client_flags=""` Default: *undefined*

**reset**
A boolean attribute that when set, resets the database connection back to its original state. If the tag is used as a container, resetting is done automatically on the closing tag pair without the need of the `reset` attribute. When rah\_swap’s tags are used as self-closing single tags, use `reset` when you want to resume to Textpattern’s original database connection.
Example: `reset` Default: *undefined*

**link**
Name of predefined database credentials config item. If the `link` attribute is defined, the used credentials are pulled from a pre-defined config array variable, `$rah_swap`, stored in Textpattern’s configuration file, `config.php`.
Example: `link="template_db"` Default: *undefined*

Configuration
-------------

[](#configuration)

With the help of the tag’s `link` attribute, database connection credentials can be saved to Textpattern’s configuration file (i.e. `/textpattern/config.php`) instead of them being specified with the tag attributes.

Defining the database’s connection credentials is done basically in the same way as Textpattern’s core database details are defined. Rah\_swap expects a global variable named as `$rah_swap`, containing a multi-dimensional array, allowing multiple links to be configured. Example config would look similar to following:

```
$rah_swap['link1'] = [
    'db' => 'MyDatabase1',
    'user' => 'MyUsername1',
    'pass' => 'MyPassword1',
    'host' => 'localhost',
];
```

```
$rah_swap['link2'] = [
    'db' => 'MyDatabase2',
    'user' => 'MyUsername2',
    'pass' => 'MyPassword2',
    'host' => 'localhost',
];
```

Where `link1` and `link2` would be the name of the link configurations and would be used as a `rah_swap` tag’s `link` attribute’s value.

```

```

Examples
--------

[](#examples)

### Simple usage example

[](#simple-usage-example)

The contents wrapped in the `` tags will be pulled from database named as **promotional\_content\_db**.

```

```

In the example `promotional_content_db` would be a database used by second Textpattern installation. The installation would be used to host promotional content and campaigns redistributed to multiple sites.

### Showing downloads from a second installation

[](#showing-downloads-from-a-second-installation)

```

```

Above serves file downloads from **downloads** database using Textpattern’s [file tags](https://docs.textpattern.com/tags/file-tags).

### As a self-closing tag

[](#as-a-self-closing-tag)

Templates are going to be fetched from **templates** database.

```

```

The connection is reset back to normal using the `reset` attribute.

Changelog
---------

[](#changelog)

### Version 0.2.0 – 2022/04/17

[](#version-020--20220417)

- Textpattern &gt;= 4.7.0 and PHP &gt;= 7.0 compatibility.
- Now requires Textpattern &gt;= 4.7.0.

### Version 0.1.0 – 2013/05/06

[](#version-010--20130506)

- Initial release.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance40

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3267 days

Total

2

Last Release

1489d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a34b4e1b662cd2c926e8e89a76f93df266b199fe61508d38026cb952f28e59e?d=identicon)[rah](/maintainers/rah)

---

Top Contributors

[![gocom](https://avatars.githubusercontent.com/u/665186?v=4)](https://github.com/gocom "gocom (15 commits)")

---

Tags

phptextpatterntextpattern-pluginplugintextpattern

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/rah-rah-swap/health.svg)

```
[![Health](https://phpackages.com/badges/rah-rah-swap/health.svg)](https://phpackages.com/packages/rah-rah-swap)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
