PHP - ayuda me inserta datos vacios desde xml a base de datos mysql php

 
Vista:

ayuda me inserta datos vacios desde xml a base de datos mysql php

Publicado por carlos (1 intervención) el 08/11/2018 18:52:29
Tengo un programa en php que lee un xml y inserta los datos en una base mysql pero cuando lo ejecuto me inserta solo datos vacios. Acontinuacion coloco el xml y el codigo que estoy usando:

XML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?xml version="1.0" encoding="utf-8"?>
 
  <UBLExtensions>
    <UBLExtension>
      <ExtensionContent>
 
          <InvoiceControl>
            <InvoiceAuthorization>320001</InvoiceAuthorization>
            <AuthorizationPeriod>
              <StartDate>2014-01-13</StartDate>
              <EndDate>2015-01-13</EndDate>
            </AuthorizationPeriod>
            <AuthorizedInvoices>
              <Prefix>PR</Prefix>
              <From>769700</From>
              <To>769702</To>
            </AuthorizedInvoices>
          </InvoiceControl>
          <InvoiceSource>
            <IdentificationCode>CO</IdentificationCode>
          </InvoiceSource>
          <SoftwareProvider>
            <ProviderID>90030</ProviderID>
            <SoftwareID>a9c0758b-735b-4951</SoftwareID>
          </SoftwareProvider>
          <SoftwareSecurityCode>8f9d9d22d4c3381a0282e8f3beb</SoftwareSecurityCode>
 
      </ExtensionContent>
    </UBLExtension>
    <UBLExtension>
      <ExtensionContent />
    </UBLExtension>
 
  </UBLExtensions>

CODIGO PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
$conn = mysqli_connect("localhost", "root", "", "facturacion");
 
$affectedRow = 0;
libxml_use_internal_errors ( true );
$xml = simplexml_load_file("PI-Pirelli-001-7697004318.xml") or die("Error: Cannot create object");
 
foreach ($xml->children() as $row) {
 
 
$DIN_INVOICE_AUTHORIZATION = $row->InvoiceAuthorization;
$DDA_START_DATE = $row->StartDate;
$DDA_END_DATE = $row->EndDate;
$DVC_PREFIX = $row->Prefix;
$DIN_FROM = $row->From;
$DIN_TO = $row->To;
$DCH_IDENTIFICATION_CODE = $row->IdentificationCode;
$DIN_PROVIDERID = $row->ProviderID;
$DVC_SOFTWAREID = $row->SoftwareID;
$DVC_SOFTWARESECURITYCODE = $row->SoftwareSecurityCode;
 
    $sql = "INSERT INTO fed_ublextensions(DIN_INVOICE_AUTHORIZATION, DDA_START_DATE, DDA_END_DATE, DVC_PREFIX, DIN_FROM, DIN_TO, DCH_IDENTIFICATION_CODE, DIN_PROVIDERID, DVC_SOFTWAREID, DVC_SOFTWARESECURITYCODE) VALUES ('" . $DIN_INVOICE_AUTHORIZATION . "','" . $DDA_START_DATE . "','" . $DDA_END_DATE . "','" . $DVC_PREFIX . "','" . $DIN_FROM . "','" . $DIN_TO . "','" . $DCH_IDENTIFICATION_CODE . "','" . $DIN_PROVIDERID . "','" . $DVC_SOFTWAREID . "','" . $DVC_SOFTWARESECURITYCODE . "')";
 
    $result = mysqli_query($conn, $sql);
 
    if (! empty($result)) {
        $affectedRow ++;
    } else {
        $error_message = mysqli_error($conn) . "n";
    }
}
?>
<h2>Insert XML Data to MySql Table Output</h2>
 
<?php
if ($affectedRow > 0) {
    $message = $affectedRow . " records inserted";
} else {
    $message = "No records inserted";
}
 
?>
<style>
body {
        max-width: 550px;
        font-family: Arial;
}
 
.affected-row {
        background: #cae4ca;
        padding: 10px;
        margin-bottom: 20px;
        border: #bdd6bd 1px solid;
        border-radius: 2px;
        color: #6e716e;
}
 
.error-message {
        background: #eac0c0;
        padding: 10px;
        margin-bottom: 20px;
        border: #dab2b2 1px solid;
        border-radius: 2px;
        color: #5d5b5b;
}
</style>
<div class="affected-row">
    <?php  echo $message; ?>
</div>
<?php if (! empty($error_message)) { ?>
<div class="error-message">
    <?php echo nl2br($error_message); ?>
</div>
<?php } ?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 604
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

ayuda me inserta datos vacios desde xml a base de datos mysql php

Publicado por Miguel (218 intervenciones) el 10/11/2018 09:17:46
Lo mas seguro es porque las variables estén vacías, debido a que no se está obteniendo de manera correcta los nodos.
También puede ser que no sea un XML válido y/o no se esté cargando correctamente.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar