Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Inserir dados XML na tabela MySQL usando PHP


Supondo que você tenha vários 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 );
}