SoFunction
Updated on 2025-03-10

How to batch replace post content in Discuz (update database using SQL)

Today, a friend’s Discuz X2 forum needs to replace the content of the post in batches. The number of posts is tens of thousands. At the beginning, it was set up to filter words. It was found that there was no effect and it could only be replaced in batches through the database. Please continue to read the specific method.

The Discuz X2 forum background provides database SQL statement operation function, but by default, this function is turned off for security reasons, so you have to modify the configuration file first, the method is as follows:

Find the forum program file config/config_global.php, open the file with Notepad, and then look for $_config['security']['querysafe']['status'] to set it to 0, and continue to look for $_config['admincp']['runquery'] to set it to 1. (For security reasons, it is recommended to change the values ​​of these two parameters after executing the SQL statement)

Here are some ways to modify the content of the post in batches on Discuz X2:

1. Enter Discuz X2 backend → Webmaster → Database → Upgrade

2. Enter the following statement and submit it:

Copy the codeThe code is as follows:

UPDATE pre_forum_post SET message=REPLACE(message,""Content to be replaced",""New content"");