
18/05/2019, 14:57
|
 | | | Fecha de Ingreso: noviembre-2012 Ubicación: Lima
Mensajes: 51
Antigüedad: 12 años, 4 meses Puntos: 0 | |
Apoyo con carga de datos excel a myslq php Saludos a todos.
estoy creando un código para cargar los datos de un archivo excel e insertarlos en mysql. pero tengo problemas con la columna de hora.
el archivo excel tiene el formato hora, como muestra la imagen.
he probado usar el tipo dato TIME de mysql pero solo me guarda en todos los registros
la hora con este valor :21:27:50.
este es parte de mi codigo con el que inserto en mi tabla lo que tengo en el archivo excel.
Código:
$horae= $fields[15]; //no se puede guradr formato hora
$horae=date('H:i:s'); ///todo lo guarda commom 21:27:50
también he probado colocar el tipo varchar para el campo de hora, y al gurdar lo hace de esta forma 
de verdad agradeciera su ayuda con este problema.
aqui dejo el link de mi proyecto en github https://github.com/gnavarro82/sistem...da_datos_linde
Código:
<h1>Carga de Datos de Pedidos Linde a Mysql con PHP</h1>
<?php
include('simplexlsx.class.php');
$host = "localhost";
$user = "root";
$pass = "navarro";
$database = "pedidos";
//set de caracteres que va tener la conexin
$charset = "utf8";
$opt = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC];
$conn = new pdo("mysql:host={$host};dbname={$database};charset=$charset", $user,$pass, $opt);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*prueba conexion pdo
if($conn){
echo "ok";
}else{
echo "falla";
}
*/
$xlsx = new simpleXLSX('pedidos.xlsx');
//consulta
$stm = $conn->prepare("INSERT INTO pedidos (guiat,ruc,gr,numrem,fechaemi,razons,direc,localidad,tarifa,pcobro,tbultos,tpeso,recibe,dni,fechaent,horae,obser,item1,item2,item3,item4,item5,item6,item7,item8,item9,item10,item11,item12) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
//envio de parametros
$stm->bindParam(1, $guiat);
$stm->bindParam(2, $ruc);
$stm->bindParam(3, $gr);
$stm->bindParam(4, $numrem);
$stm->bindParam(5, $fechaemi);
$stm->bindParam(6, $razons);
$stm->bindParam(7, $direc);
$stm->bindParam(8, $localidad);
$stm->bindParam(9, $tarifa);
$stm->bindParam(10, $pcobro);
$stm->bindParam(11, $tbultos);
$stm->bindParam(12, $tpeso);
$stm->bindParam(13, $recibe);
$stm->bindParam(14, $dni);
$stm->bindParam(15, $fechaent);
$stm->bindParam(16, $horae);
$stm->bindParam(17, $obser);
$stm->bindParam(18, $item1);
$stm->bindParam(19, $item2);
$stm->bindParam(20, $item3);
$stm->bindParam(21, $item4);
$stm->bindParam(22, $item5);
$stm->bindParam(23, $item6);
$stm->bindParam(24, $item7);
$stm->bindParam(25, $item8);
$stm->bindParam(26, $item9);
$stm->bindParam(27, $item10);
$stm->bindParam(28, $item11);
$stm->bindParam(29, $item12);
function fexcel2unix($f){
return ($f-25568)*86400;
}
foreach ($xlsx->rows() as $fields) {
$guiat = $fields[0];
$ruc = $fields[1]; //no guarda el ruc commo deberia ser
$gr = $fields[2];
$numrem = $fields[3];
$fechaemi= date("Y-m-d", fexcel2unix($fields[4]));
$razons= $fields[5];
$direc= $fields[6];
$localidad= $fields[7];
$tarifa= $fields[8];
$pcobro= $fields[9];
$tbultos= $fields[10];
$tpeso= $fields[11];
$recibe= $fields[12];
$dni= $fields[13];
$fechaent= $fechaemi;
$horae= $fields[15]; //no se puede guradr formato hora
//$horae=date('H:i:s'); ///todo lo guarda commom 21:27:50
$obser= $fields[16];
$item1= $fields[17];
$item2= $fields[18];
$item3= $fields[19];
$item4= $fields[20];
$item5= $fields[21];
$item6= $fields[21];
$item7= $fields[22];
$item8= $fields[23];
$item9= $fields[24];
$item10= $fields[25];
$item11= $fields[26];
$item12= $fields[27];
$stm->execute();
}
?>
__________________ Gracias por todo. |