Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

big replace in mysql table

  • 22-04-2007 11:51PM
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    any one know how i replace ’ with ' in a big mysql database table ?

    tnx


Comments

  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Do you want to run through the database and replaces it in the content, or just replace the characters as they are returned from a query?


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    HI
    id like to run through the db if possible.
    its just one field on teh table im interested in, in fact

    tnx


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    One way is by doing a query select from the table where field like "'’%'" then loop through records and use the str_replace("’","'",field) or preg_replace functions, then update database with the new value.

    Depending on the amount of records you have it might take a while.


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    MySQL has a replace function :)
    UPDATE 
        myTable 
    SET
        myVarCharCol = REPLACE(myVarCharCol, '’', '\'')
    
    Details here:
    http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

    It may be worth your while building a fulltext index on the column in question to speed it up, but assuming it's a once-off replace, that would be overkill.

    Backup your table/database first!


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    Perfect seamus - that worked like a charm! TNX


  • Advertisement
Advertisement