Thursday 22 September 2011

Removing special characters from Mysql database

I have two ideas to remove extra unnecessary special characters. If we are adding data directly to database through form or some other means and don't have control over the type of data inserted than we can use this simple query right after the mysql_connect( ) call:
 mysql_query("SET NAMES 'utf8'");
And than your insert query such as $query=mysql_query("INSERT into tablename VALUES(value1,value2,...)");


Another way is if data is already stored in database and we want to show data without special characters such as in xml feeds or some other form than we can update the database table with following query:
UPDATE tablename SET fieldname = replace(fieldname,"word_to_replace","with_this_word");


Suppose we have to replace 'he' with 'him' in whole row of a database table than we can use above query as:
UPDATE tablename SET row-name = replace(row-name,"he","him");

Hope this might help you.;)


More information on www.narendrarathore.com

No comments:

Post a Comment