I'm trying to import a product csv using PHP to MySQL
. When i try to import I got strange characters which also not add properly to database table
.
Product Name on CSV File
Alva Cook'on Braadpan Lavendelblauw ovaal 24 cm – 4,2 Liter
Product name i got when import function execute
Alva Cook'on Braadpan Lavendelblauw ovaal 24 cm – 4,2 Liter
my code is like
while (($emapData = fgetcsv($filepath, 10000, ",")) !== FALSE)
{
$pd_name= ($emapData[1]);
}
i used this function as a solution this shows product name correctly on import page
$pd_name=mb_convert_encoding(($emapData[1]), 'UCS-2LE', 'UTF-8');
Output ~ Alva Cook'on Braadpan Lavendelblauw ovaal 24 cm – 4,2 Liter
But when i use mysql_real_escape_string
as below for insert the name to db table, it added lots of slashes
and not work properly.
$pd_name=mysql_real_escape_string(mb_convert_encoding(($emapData[1]), 'UCS-2LE', 'UTF-8'));
Output ~ A\0l\0v\0a\0 \0C\0o\0o\0k\0\'\0o\0n\0 \0B\0r\0a\0a\0d\0p\0a\0n\0 \0L\0a\0v\0e\0n\0d\0e\0l\0b\0l\0a\0u\0w\0 \0o\0v\0a\0a\0l\0 \02\04\0 \0c\0m\0 \0 \04\0,\02\0 \0L\0i\0t\0e\0r\0
SQL database
table supports UTF
and when we add products normally using form we don't face this problem, anyone know how to fix this issue. Thank You