Foros del Web » Programando para Internet » PHP »

Problema al importar datos csv

Estas en el tema de Problema al importar datos csv en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 26/09/2008, 12:37
(Desactivado)
 
Fecha de Ingreso: mayo-2008
Mensajes: 67
Antigüedad: 15 años, 10 meses
Puntos: 0
Problema al importar datos csv

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";
 

Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:58.