Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

big replace in mysql table

Options
  • 22-04-2007 11:51pm
    #1
    Registered Users 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 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 Posts: 68,317 ✭✭✭✭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 Posts: 648 ✭✭✭ChicoMendez


    Perfect seamus - that worked like a charm! TNX


  • Advertisement
Advertisement