Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $xmlDoc = new DOMDocument();
- $xmlDoc->load('example.xml');
- $mysql_hostname = 'localhost'; // Example : localhost
- $mysql_user = 'alb88945_admin_1';
- $mysql_password = 'dEu)~XUAN3JW';
- $mysql_database = 'alb88945_mediaging';
- $dbh = new PDO("mysql:dbname={$mysql_database};host={$mysql_hostname};port=3306", $mysql_user, $mysql_password);
- $xmlObject = $xmlDoc->getElementsByTagName('annuncio');
- $itemCount = $xmlObject->length;
- for ($i=0; $i < $itemCount; $i++){
- $name = $xmlObject->item($i)->getElementsByTagName('id_annuncio_immobile')->item(0)->childNodes->item(0)->nodeValue;
- // $link = $xmlObject->item($i)->getElementsByTagName('url')->item(0)->childNodes->item(0)->nodeValue;
- $sql = $dbh->prepare("INSERT INTO `my_table_name`(`title`) VALUES (?)");
- $sql->execute(array(
- $name,
- // $link
- ));
- print "Finished Item $name n<br/>";
- // inizio secondo ciclo
- for ($i=0; $i < $itemCount; $i++){
- $link = $xmlObject->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
- // $link = $xmlObject->item($i)->getElementsByTagName('url')->item(0)->childNodes->item(0)->nodeValue;
- $sql = $dbh->prepare("INSERT INTO `my_table_name_2`(`link`) VALUES (?)");
- $sql->execute(array(
- $link
- // $link
- ));
- }
- // fine secondo ciclo
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement