Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-04 18:33:57

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 259
Website

rah_swap plugin with table_prefix

I’m attempting to access another TXP database (with a table_prefix) on the same server using rah_swap.

<rah::swap db="a" user="b" pass="c" host="localhost:3306">etc

I’m getting nada, but I suspect its ‘cos I’m not specifying the prefix. I can remove the prefix on the master db, but is there a simpler solution?

Thanks!

Offline

#2 2021-03-04 20:30:23

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: rah_swap plugin with table_prefix

Interesting question. rah_swap just switches the database connection temporarily and the code is so sparing, I can’t tell if setting table_prefix will have any effect. If I’m not mistaken, the table prefix is independent of the connection and is always inserted as part of the database query. When we install Textpattern, it’s asked as part of the installation routine but stored as constant called PFX that is then used in Textpattern’s database query functions.

Two ideas:

  • Use smd_query so that you can specify the table prefix as part of the table attribute but then process using txp:tags.
  • Change the PFX constant in a txp:php block after swapping db connections with rah_swap, the reset it again after returning to your regular database. You can see how that’s done in Textpattern here.

I bet someone else can give you a more authoritative answer :-)


TXP Builders – finely-crafted code, design and txp

Offline

#3 2021-03-05 18:22:34

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 259
Website

Re: rah_swap plugin with table_prefix

To keep things easy for myself when I revisit this aspect of the code in the future, I think I’ll remove the prefix on the master database (its long been redundant in any case).

Thank you.

Offline

Board footer

Powered by FluxBB