hi i have a big database with lots of customers comments. i want to copy all the data to a new database [changing the software and importing old data] customers coments contains HTML as well and special cheracters as well Example 1 Example 2 when i select data from database using php and try to save it in new DB query often gets terminated due to special cheractors $query="insert into comments (id,custkey,date,cdata) values('$id','$custkey','$NowDate','$oldDBcomments')"; mysql_query($query,$link); PHP: My main question you can say is how can i save data that contains special cheracters like ' , & , " , / , \ in mysql database using php my main goal is to copy customers comments from one database to an other . customers comments contains HTML as well thanks in advance
htmlentities (PHP 3, PHP 4, PHP 5) htmlentities -- Convert all applicable characters to HTML entities Description string htmlentities ( string string [, int quote_style [, string charset]] ) This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities. Like htmlspecialchars(), the optional second quote_style parameter lets you define what will be done with 'single' and "double" quotes. It takes on one of three constants with the default being ENT_COMPAT:
mysql_escape_string (PHP 4 >= 4.0.3, PHP 5) mysql_escape_string -- Escapes a string for use in a mysql_query Description string mysql_escape_string ( string unescaped_string ) This function will escape the unescaped_string, so that it is safe to place it in a mysql_query(). This function is deprecated. This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting.
Use a function called mysql_real_escape_string() like this $query="insert into comments (id,custkey,date,cdata) values('" . mysql_real_escape_string($id) . "','" . mysql_real_escape_string($custkey) . "','" . mysql_real_escape_string($NowDate) . "','" . mysql_real_escape_string($oldDBcomments) . "')"; mysql_query($query,$link); Code (markup): HTH, cheers!