Global Post Text Find and Replace

This is something that many board administrators want to do but aren't sure how—messing with the database directly seems dangerous to many. It is quite simple though, and you can do it all through the AdminCP.

Log into the AdminCP, and in the left-hand menu click on Import & Maintenance followed by Execute SQL Query. If you are greeted with a message that says: You are not authorized to execute SQL queries you will need to add your user ID number to the line: $canrunqueries = ''; in the includes/config.php file. For example, if your user ID is 1, this line will become: $canrunqueries = '1';

Now you can run queries. To carry out a find and replace on all the post data in your board, you will need to run an SQL query like this: UPDATE post SET pagetext = REPLACE (pagetext,'Vbulletin','vBulletin') WHERE pagetext LIKE '% Vbulletin%';

This SQL query looks through the posts for instances of Vbulletin and replaces them with vBulletin. The WHERE clause is used to optimize the find and replace as this allows MySQL to take advantages of indexes, which speeds things up.

If you get an error running this query then check to see if you are using a table prefix in the database for the tables (such as vb_) and add this to the query. This would change the query to the following: UPDATE vb_post SET pagetext = REPLACE (pagetext,'Vbulletin','vBulletin') WHERE pagetext LIKE '% Vbulletin%';

If you wanted to carry out a similar find and replace within PMs, you'd use the following query: UPDATE pmtext SET message = REPLACE (message,'Vbulletin','vBulletin') WHERE message LIKE '%Vbulletin%';

By using MySQL queries you are taking total control over the data held in the database. We don't have the time or scope here to cover MySQL queries in detail, so for more information visit http://dev.mysql.com. Alternatively, you can read Mastering phpMyAdmin for Effective MySQL Management by Marc Delisle, published by Packt Publishing (ISBN 1-904811-03-5).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset