HOLA TENGO UN PROBLEMA EN ESTE CODE IMPORTA TODO LOS DATOS DE UN CSV A UNA TABLA MYSQL PERO EL PROBLEMA ES EN LOS CAMPOS VARCHAR LOS DATOS SON IMPORTADOS ANTEPONIEDOCE UNA COMILLA DOBLE
EJEMPLO EN VES DE IMPORTAR imagen.jpg Importa "imagen.jpg" como tendria que hacer para que me importe sin las comillas en los campos varchar. Código PHP:
function db_connect()
{
$result = @mysql_pconnect("localhost", "user", "pass");
if (!isset($result) && empty($result))
{echo "can't connect!"; }
if (!@mysql_select_db("mibd"))
return false;
return $result;
}
$conn = db_connect();
$result = mysql_query($query);
$csv=$_POST['csv'];
$csv="$csv.csv";
$fcontents = file ($csv);
# expects the csv file to be in the same dir as this script
# we start counter at 1 to avoid first row of csv which only is there to force a correct col number
# ref to col title
for($i=1; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line); // $arr=print_r($arr);echo"$arr";
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$table="productos";
$sql = "insert into $table values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo ".";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
else
{
echo "error";
}