sql >> Base de Datos >  >> RDS >> Mysql

Insertar datos XML en la tabla MySQL usando PHP

Suponiendo que tiene varios clientes...

$sXmlString =<<< END
<?xml version="1.0"?>
<Content>
<Customer>
<id>1</id>
<name>Oluwafemi</name>
<address>Cresent Drive, TX</address>
</Customer>
<Customer>
<id>2</id>
<name>Oluwafemi2</name>
<address>Cresent Drive 2, TX</address>
</Customer>
</Content>
END;

$oXml       = simplexml_load_string($sXmlString);
$sJson      = json_encode( $oXml );
$aContent   = json_decode( $sJson, TRUE );
$aCustomers = $aContent[ 'Customer' ];
var_dump( $aCustomers );
$iCountCustomers = count( $aCustomers );
for( $i = 0; $i < $iCountCustomers; ++$i )
{
    $sId      = $aCustomers[ $i ][ 'id' ];
    $sName    = $aCustomers[ $i ][ 'name' ];
    $sAddress = $aCustomers[ $i ][ 'address' ];
    var_dump( $sId );
    var_dump( $sName );
    var_dump( $sAddress );
}