Replacing Text In A MySQL Database Using PHP

by Ben Sinclair
Webmaster-Resources101.com
Thursday, 28th July 2005

This tutorial is short and straign to the point.

You may have the word Ben in a lot of the MySQL rows and want to repalce that word with a new word such as Jim. If you have 10+ of rows with the name Ben 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:

<?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...
?>

Replace table_name and text with your own database fields and you're all set! Pretty simple huh?

Enjoy! :)


Options:
Printer Friendly
Email Friend

About The Author:

Ben Sinclair is the webmaster of Webmaster-Resources101.com, Webmaster-Forums101.com and DevTutors.com

Developer Categories



Developer Tutorials
ASP
CGI & Perl
CSS
Flash
HTML
Java
JavaScript
MySQL
PHP
Python
XML

Developer Documentation

Developer Tools



Search our Developer Tutorials
  The DevSyndicate Network