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 370,613 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,100 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:
Views: 7824 | Replies: 11
Reply
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 107
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Find and Replace

  #1  
Aug 6th, 2003
When upgrading these boards from phpBB to vBulletin, I encountered a few errors in the posts. One of these is that the old style stores quotes as " and it is printed out verbatim in the posts.

Is there a find and replace SQL statement to traverse through a record of posts replacing all instances of " with " ??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2002
Location: New York
Posts: 862
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Rep Power: 12
Solved Threads: 15
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Find and Replace

  #2  
Aug 6th, 2003
Nope :-(. You need to write a php script (or, whatever language you want) to retrieve all the records, fix each record, and then shove it back to the dictionary.
-Ryan Hoffman

ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 107
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Find and Replace

  #3  
Aug 6th, 2003
Ooh that's yucky news. Oh well. Guess if that's what I have to do, off I go to read up on my php.
Reply With Quote  
Join Date: Jul 2002
Posts: 71
Reputation: evilmonkey29 is an unknown quantity at this point 
Rep Power: 6
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  
Join Date: Jul 2002
Posts: 71
Reputation: evilmonkey29 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 1
evilmonkey29 evilmonkey29 is offline Offline
Junior Poster in Training
  #5  
Aug 6th, 2003
on the str_replace line, thats:

$newtext = str_replace("AMPERSAND Q U O T SEMICOLON", 'REGULAR DOUBLE QUOTE', $row['text']);
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 107
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Find and Replace

  #6  
Aug 7th, 2003
It didn't work. I just kept getting MySQL errors in the middle of reading the first post. I tweaked some stuff and got it to edit stuff halfway thru the database until it got stuck. Then I restored a previous version of the database.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 107
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Find and Replace

  #7  
Aug 7th, 2003
This must be like the fifth time I'm responding to this post! I respond. I find a problem. I restore the database. I respond. I find a problem w/ the database. I restore the database. I keep restoring to about 5 minutes ago LOL.

In any case, I finally cheated. I dumped the database into an .sql file. I did a find/replace in Microsoft Word. Then I imported everything back into the database.

Unfortunately, there are still a few differences between the board softwares that I need this find/replace utility for. I'd reallllly like to be able to get this php script working. It seems simple enuf, no? Does anyone know why this doesn't work or how to get it to work?

Thanks!
Reply With Quote  
Join Date: Jul 2002
Posts: 71
Reputation: evilmonkey29 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 1
evilmonkey29 evilmonkey29 is offline Offline
Junior Poster in Training
  #8  
Aug 7th, 2003
Dani, the script appears fine. How you implemented it isn't. There is only so much I can do with the given information. Please include a copy of the error message, along with a copy of your edited code (except the password of course), and a simple table layout explanation. Also include your PHP version.
Sorry this has been giving you trouble and I'll be glad to help, just need some more info.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 107
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Find and Replace

  #9  
Aug 7th, 2003
It got through the first few posts. However, for some reason, it seemed to have gotten stuck halfway through reading one of the earlier posts. I'm not sure exactly what prompted it to suddenly crash and burn on me.
Reply With Quote  
Join Date: Feb 2002
Location: New York
Posts: 862
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Rep Power: 12
Solved Threads: 15
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Find and Replace

  #10  
Aug 7th, 2003
Heh... This is kinda OT, but this thread is a great example on how good TTF really is.

When someone is having a problem (even the administrator!) there is always someone to help with it.

Just had to compliment all the members of TTF for this amazing dream to become a reality.
-Ryan Hoffman

ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Database Design Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Database Design Forum

All times are GMT -4. The time now is 6:50 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC