Good day, I have the following problem, I hope you can help me. I want to import an XML file into a MySQL database using the following code. My XML file is the following:
<xml>
<clubnet>01/12/2017</clubnet>
<escuelas>
<escuela>
<escuela>01</escuela>
<Domicilio>FAJARDO# 163</Domicilio>
<ciudad>ZAMORA</ciudad>
<estado>MICHOACAN</estado>
<encargado>PROF. JUANPEREZ</encargado>
<telefono>3511231222</telefono>
<Nombre>TAEKWONDO</Nombre>
<Registro>.</Registro>
<Folio>0</Folio>
<puesto>PROFESOR ESCUELA</puesto>
<referencia>E.C</referencia>
<status>0</status>
<escuelapadre>.</escuelapadre>
</escuela>
</escuelas>
</xml>
AND THE PHP CODE IS THE FOLLOWING:
<?php
$xml_file = 'escuelas_2.xml';
if (file_exists($xml_file)) {
$xml = simplexml_load_file($xml_file);
echo "ARCHIVO XML CARGADO EXITOSAMENTE <br><br>";
}
else {
exit('Error al intentar abrir el fichero '.$xml_file);
}
require 'conexion.php';
$count=0;
foreach ($xml->escuelas as $escuela) {
$qry = "INSERT INTO escuelas (escuela, Domicilio, ciudad, estado, encargado,telefono,Nombre , Registro, Folio,puesto, referencia,status,escuelapadre)
VALUES ('$escuela->escuela','$escuela->Domicilio','$escuela->ciudad','$escuela->estado','$escuela->encargado','$escuela->telefono','$escuela->Nombre','$escuela->Registro','$escuela->Folio','$escuela->puesto','$escuela->referencia','$escuela->status','$escuela->escuelapadre')";
$resultado=mysqli_query($link,$qry) or die(mysqli_error());
if($resultado)
echo "INSERCIÓN REALIZADA CON EXITO";
else
echo "INSERCIÓN NO REALIZADA";
$count++;
}//foreach
echo "
"; echo "-------------------------------------------
"; echo "Total de escuelas importadas: $count properties
"; echo "-------------------------------------------
";
?>