Welcome to Webmaster Resources 101


Our Network:

Replacing Text In A MySQL Database Using PHP

[ About This Author :: Request Reprint :: Print Article :: Tell A Friend ]

Replacing Text In A MySQL Database Using PHP

By Ben Sinclair
http://www.webmaster-resources101.com

You may have the word <b>Ben</b> in a lot of your MySQL rows and want to repalce that word with a new word such as <b>Jim</b>.

If you have 10+ of rows with the name <b>Ben</b> in it, it could take a while having to modify each table manually...

Here is a quick and easy way to do it all at once with some simple PHP and MySQL:

<font color="green"><?php
// Connect to your MySQL Database here etc...

// Now with the MySQL Query
mysql_query("update table_name set text=REPLACE(text,'Ben','Jim')");

// Rest of your PHP code...
?></font>
Replace <i>table_name</i> and <i>text</i> with your own database fields and you're all set!

Pretty simple huh?

Enjoy! :)

 
Other Related Material:

Discuss this in our Webmaster Forums

About The Author:
Ben Sinclair
http://www.webmaster-resources101.com
Ben Sinclair is the Webmaster of Webmaster Resources 101 and Webmaster Forums 101.
Go To Top

This article has been read 1196 times.

[ About This Author :: Request Reprint :: Print Article :: Tell A Friend ]