SQL to update URL's

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6410
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

SQL to update URL's

Post by thecoalman »

I only need to run this once so efficiency is irrelevant, how do I get the placeholder into the select statement?

Code: Select all

UPDATE phpbb_posts SET post_text = REGEXP_REPLACE
(
    post_text, 

    'http://example.com/about([0-9]{1,5}).html', 
    

    CONCAT('https://example.com/forum/viewtopic.php?f=' , (SELECT `forum_id` FROM phpbb_topics WHERE `topic_id` = '\\1')  , '&t=\\1')
)
This returns 0 results presumably because it's looking for \\1 instead of the placeholder value. Testing this changing the placeholder \\1 to an actual topic ID works but obviously it's wrong value. Just so it's clear there isno issue with the placeholder in '&t=\\1'
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6410
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: SQL to update URL's

Post by thecoalman »

Any help with this? If I can get this to work as outlined it would be very helpful now and in the future.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
RMcGirr83
Former Team Member
Posts: 22071
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: SQL to update URL's

Post by RMcGirr83 »

Maybe I don't understand but what populates this?
the placeholder value
Are you running this directly in phpmyadmin or within a PHP file?
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6410
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: SQL to update URL's

Post by thecoalman »

RMcGirr83 wrote: Fri Sep 08, 2017 12:35 pm Maybe I don't understand but what populates this?
It's using regex. :D

Code: Select all

 'http://example.com/about([0-9]{1,5}).html'
That gets me the topic ID and it's held in the placholder \\1

If I just wanted to do this it will work fine.

Code: Select all

UPDATE phpbb_posts SET post_text = REGEXP_REPLACE
(
    post_text, 

    'http://example.com/about([0-9]{1,5}).html', 
    

    'https://example.com/forum/viewtopic.php?t=\\1')
)


I have been using this right in phpMyadmin for many one off queries for a pattern match. This for example will get the correct forum ID for the topic 12345 from the topics table assuming there is topic ID in the topics table 12345

Code: Select all

UPDATE phpbb_posts SET post_text = REGEXP_REPLACE
(
    post_text, 

    'http://example.com/about([0-9]{1,5}).html', 
    

    CONCAT('https://example.com/forum/viewtopic.php?f=' , (SELECT `forum_id` FROM phpbb_topics WHERE `topic_id` = 12345)  , '&t=\\1')
)
The issue is getting topic ID held in placeholder into the select statement.
Last edited by thecoalman on Fri Sep 08, 2017 1:42 pm, edited 2 times in total.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

Return to “phpBB Custom Coding”