Load text file to mysql from form, using sql script and php

0

I'm trying to do the text file upload using sql script, try:

  • Do not take into account the first row that corresponds to the headers.

The table where it will be inserted has a defined id id field, the file does not contain that field, so I look for the other fields to be inserted in the table, but:

  • Something is missing in the script for the first field in the table to skip, and to increase it according to the insertion of the other fields.

And that this sql script contained in a php function can be called at the moment of pressing a button on a form. But I can not make this link.

I thank you in advance for your attention:

public function carga306()
  {
    $sql = "load data local infile 'c:\ventas\ventas.txt' into table ventas306 
            fields terminated by '¶' lines terminated by 'Þ' IGNORE 1 LINES 
            (@fecha_contable, @fecha_apertura, @fecha_salida, @fecha_venta, @fecha_cierre)
            SET fecha_contable = STR_TO_DATE(@fecha_contable, "%Y %M %d"),
            SET fecha_apertura = STR_TO_DATE(@fecha_apertura, "%Y %M %d"),
            SET fecha_salida = STR_TO_DATE(@fecha_salida, "%Y %M %d"),
            SET fecha_venta = STR_TO_DATE(@fecha_venta, "%Y %M %d"),
            SET fecha_cierre = STR_TO_DATE(@fecha_cierre, "%Y %M %d")";

    return ejecutarConsulta($sql); 
  }

Formulario y script que invoca la función del script. 

<?php

require "../config/Conexion.php";
require_once "../modelos/Ventas.php";

$vtas = new Ventas(); //objeto del modelo Ventas 
 
    if ( isset($_POST["envio"]) ) 
    {
    	echo "Cargando...";

        $insert_vtas = $vtas->carga306(); //incocando la funcíon del modelo

        echo "Hecho";

    }

?>

<form method="POST" action="../controles/load_ventas2.php" enctype="multipart/form-data">
                <br>  
                <label for="a_venta">Cargar txt Archivo Ventas 306:</label>
                <br>             
           <div class='col-xs-6'>
           <h3 class='text-right'>   
           <input type="submit" name="envio" id="envio" class="btn btn-success" value="Carga">
           </h3>
           </div>  
       </form>

File Format

Clave Area¶Area de Venta¶F. Contable¶Sesión¶Fecha de Apertura¶Hora de Apertura¶AV/P¶Transacción¶Operación¶ID DE VTA¶Tipo¶Origen¶Destino¶Fecha Salida¶Hora Salida¶Folio Boleto¶Asiento¶Nombre Pasajero¶Tipo¶Formas de Pago¶EF¶TB¶PU¶TR¶DO¶GP¶CV¶Importe¶Formato/Salto¶Fecha Venta¶Hora Venta¶Corrida¶Empresa Corrida¶Tipo de Boleto¶Numero de Referencia¶Clave de Autorizacion¶Voucher¶Tipo de Servicio¶F. Cierre¶Razon Social¶R.F.C.¶DOCUMENTO ¶ EMPRESA¶

006¶ACAPULCO CENTRO¶01/01/2016¶231658¶01/01/2016¶06:44:22¶ACAEE67892¶5155690¶7978798¶¶CS¶ACAC¶OMET¶01/01/2016¶12:15¶T-A-04131772¶13¶GRISELDA BARAJAS GUERRERO¶¶EF¶146.00¶0.00¶0.00¶0.00¶0.00¶0.00¶0.00¶146.00¶¶01/01/2016¶07:49:40¶028376¶AUTOTRANSPORTES COSTEñOS¶ADULTO¶00000000000000000000¶¶0¶ECONOMICO¶01/01/2016¶¶¶0¶¶Þ
006¶ACAPULCO CENTRO¶01/01/2016¶231658¶01/01/2016¶06:44:22¶ACAEE67892¶5155690¶7978799¶¶CS¶ACAC¶OMET¶01/01/2016¶12:15¶T-A-04131773¶14¶MARGARITA CARVAJAL NAVA¶¶EF¶146.00¶0.00¶0.00¶0.00¶0.00¶0.00¶0.00¶146.00¶¶01/01/2016¶07:49:40¶028376¶AUTOTRANSPORTES COSTEñOS¶ADULTO¶00000000000000000000¶¶0¶ECONOMICO¶01/01/2016¶¶¶0¶¶Þ
    
asked by Armando Arellano 01.03.2018 в 20:09
source

0 answers