Foros del Web » Programando para Internet » PHP »

Importar cualquier archivo .csv

Estas en el tema de Importar cualquier archivo .csv en el foro de PHP en Foros del Web. Caballeros, tengo el siguiente script: <?php $server = 'localhost'; $user = 'alvaro'; $passwort = 'alvaro'; $database = 'certifications'; $file = 'D:/CISCO OSZIMT/MySQL/import.csv'; $verbindung = mysql_connect($server, ...
  #1 (permalink)  
Antiguo 05/06/2013, 02:36
Avatar de hellsingstq  
Fecha de Ingreso: junio-2013
Ubicación: Madrid
Mensajes: 12
Antigüedad: 10 años, 10 meses
Puntos: 0
Pregunta Importar cualquier archivo .csv

Caballeros, tengo el siguiente script:

<?php
$server = 'localhost';
$user = 'alvaro';
$passwort = 'alvaro';
$database = 'certifications';
$file = 'D:/CISCO OSZIMT/MySQL/import.csv';

$verbindung = mysql_connect($server, $user, $passwort) or die ("Keine Verbindung m&ouml;glich");

if($verbindung){
$db= mysql_select_db($database) or die ("Die Datenbank existiert nicht");
$sql = "LOAD DATA LOCAL INFILE '$file'
INTO TABLE students
FIELDS TERMINATED BY ';'
ENCLOSED BY ''
LINES TERMINATED BY '\n' ";

echo mysql_error();
if($sql){
$ergebnis = mysql_query($sql);
if($ergebnis){
echo "Datas written in table $ergebnis . <br>";

}
else
{
echo "Failed to write Datas into table";
}

echo "<table border='1'>";
echo "<tr>
<th>Number</th>
<th>Name</th>
<th>Surname</th>
<th>Teacher</th>
<th>Classname</th> </tr>";
$select_data = "Select * from `students`";
$select_data = mysql_query ("Select * from `students`");
while($row = mysql_fetch_row($select_data))
{
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row[0];
echo "</td><td>";
echo $row[1];
echo "</td><td>";
echo $row[2];
echo "</td><td>";
echo $row[3];
echo "</td><td>";
echo $row[4];
echo "</td></tr>";
}

echo "</table>";
}

}
mysql_close($verbindung);
?>

Todo funciona excepto una cosa, quiero poder coger cualquier archivo, independientemente de la ruta. Como puedo hacer eso??
Gracias de antemano x la ayuda!
  #2 (permalink)  
Antiguo 05/06/2013, 06:11
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Importar cualquier archivo .csv

independientemente de la ruta todos los archivos tienen una ruta. Qué es lo que quieres lograr exactamente?
__________________
Fere libenter homines, id quod volunt, credunt.
  #3 (permalink)  
Antiguo 05/06/2013, 06:13
Avatar de hellsingstq  
Fecha de Ingreso: junio-2013
Ubicación: Madrid
Mensajes: 12
Antigüedad: 10 años, 10 meses
Puntos: 0
Respuesta: Importar cualquier archivo .csv

Pues que coja cualquier archivo, tenga la ruta que tenga y tenga el nombre que tenga, basicamente y en pocas palabras

Etiquetas: csv, mysql
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 17:51.