User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Database Design section within the Web Development category of DaniWeb, a massive community of 397,602 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,667 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Database Design advertiser:

Find and Replace

Join Date: Jul 2002
Posts: 71
Reputation: evilmonkey29 is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 1
evilmonkey29 evilmonkey29 is offline Offline
Junior Poster in Training
  #4  
Aug 6th, 2003
Actually, while PHP is useful, it is not necessary. I think you can telnet into mysql or something like that.
If you were to use a php script, here's some inefficient code:
Assuming your database was named "mydb" and your table was named "mytable" and included fields "id" and "text":
[PHP]
<?
$db = mysql_connect("localhost", "username", "password") or die(mysql_error()); //connect to mysql

mysql_select_db("mydb",$db); //select the database

$table = mysql_query("SELECT * FROM mytable", $db) or die(mysql_error()); //grab the table data

while($row = mysql_fetch_assoc($table)){ //do this for every row in the table

$newtext = str_replace(""", '"', $row['text']); //replace " with " in the text field and store that as the variable newtext

if ($newtext !== $row['text']){ //if newtext is different from the database value, then we need to update

$tmp = mysql_query("UPDATE mytable SET text = '$newtext' WHERE id = $row['id']", $db) or die(mysql_error()); //update the database

} //end if statement

} //end while loop

?>
[/PHP]
I only checked it for syntax but just IM me if you have any trouble.
Last edited by evilmonkey29 : Aug 6th, 2003 at 11:57 pm.
Reply With Quote  
All times are GMT -4. The time now is 7:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC