View Full Version : Import excel to mysql unicode issue

12-21-2006, 12:35 PM

i have a script which you can view below that will import a .csv file into a mysql table, however i get errors due to the various special characters in the spreadsheet. is there anyway i can get around this.

$fs = filesize("file.csv");

$fh = fopen("file.csv", "r");

fgets($fh, $fs);
require ('db.php');
while($row = fgetcsv($fh, $fs))


$category_id = $row["0"];
$category = $row["1"];
$manufacturer_id = $row["2"];
$manufacturer = $row["3"];
$product_name = $row["4"];
$info_text= $row["5"];
$features= $row["6"];
$specification = $row["7"];
$image_name = $row["8"];
$data_sheet = $row["9"];
$buy_price = $row["10"];

$query = "INSERT into test.test (category_id, category, manufacturer_id, manufacturer, product_name, info_text, features, specification, image_name, data_sheet, buy_price) values ('$category_id', '$category', '$manufacturer_id', '$manufacturer', '$product_name', '$info_text', '$features', '$specification', '$image_name', '$data_sheet', '$buy_price')";

$result = mysql_query ($query) or die (mysql_error());



thanks in advance

12-21-2006, 04:07 PM
Just fixed it, as it was only one character causing problems i replaced it with another before the insert then replaced to the original character when selec ting the data.