I'm trying to pull data from remote xml files to load the database of a library. My sources are www.amazon.com and www.ISBNdb.com. But when I try to search and read the xml files, I get this error:
When I open the resulting URLs in a browser, I can see the xml data just fine, and I have tried this on to different computers and servers, with the same result.
Here is my code (minus the access keys for the databases):
Any ideas appreciated.
Warning: simplexml_load_ file() [function.simple xml-load-file]: php_network_get addresses: getaddrinfo failed: No such host is known. in C:\Program Files\EasyPHP 3.0\www\loadDat abase.php on line 43
When I open the resulting URLs in a browser, I can see the xml data just fine, and I have tried this on to different computers and servers, with the same result.
Here is my code (minus the access keys for the databases):
<html>
<head>
<title>Run to Load Database</title>
</head>
<body>
<?php
$DBConnect = mysqli_connect( "localhost","ro ot","mysql") or die('Could not connect: ' . mysqli_error()) ;
/*mysqli_query($ DBConnect, "CREATE DATABASE library") or die("Unable to execute query: " . mysqli_error($D BConnect));*/
mysqli_select_d b($DBConnect, "library") or die ('Could not get database: ' . mysqli_error($D BConnect));
/*$query = "CREATE TABLE book (ISBN, smallISBN, Title VARCHAR(1000), Author VARCHAR(1000), Publisher VARCHAR(1000), pages)";
mysql_query($DB Connect, $query);*/
$query = "SELECT ISBN FROM book WHERE smallISBN=0";
$result = mysqli_query($D BConnect, $query) or die ('Could not query: ' . mysqli_error($D BConnect));
while($row = mysqli_fetch_ar ray($result))
{
$isbn = $row['ISBN'];
$completeurl = "http://ecs.amazonaws.c om/onca/xml?Service=AWS ECommerceServic e&AssociateTag= AKIAIYMXQSE3WJJ K5CHA&AWSAccess KeyId=MY_KEY&Op eration=ItemSea rch&SearchIndex =Books&Response Group=ItemAttri butes&Keywords= " .$isbn;
$completeurl2 = "http://isbndb.com/api/books.xml?acces s_key=My_KEY&in dex1=isbn&value 1=" .$isbn;
$xml = simplexml_load_ file($completeu rl) or die ("no file loaded");
$xml2 = simplexml_load_ file($completeu rl2) or die ("no file loaded2");
$smallisbn = $xml->Items->Item->ItemAttribut es->ISBN;
$title = addslashes($xml->Items->Item->ItemAttribut es->Title);
$titleLong = addslashes($xml 2->BookList[0]->BookData[0]->TitleLong);
$author = addslashes($xml 2->BookList[0]->BookData[0]->AuthorsText) ;
$publisher = addslashes($xml->Items->Item->ItemAttribut es->Publisher);
$publisher .= ", ";
$publisher .= $xml->Items->Item->ItemAttribut es->PublicationDat e;
$publisher .= ", ";
$publisher .= $xml->Items->Item->ItemAttribut es->Edition;
$publisher .= " Edition";
$dewey = $xml->Items->Item->ItemAttribut es->DeweyDecimalNu mber;
$pages = $xml->Items->Item->ItemAttribut es->NumberOfPage s;
$type = $xml->Items->Item->ItemAttribut es->Binding;
echo $isbn . " " . $smallisbn . " " . $title . " " . $author . " " . $publisher . " " . $pages . " " . $type . " " . $edition . " " . $publishdate;
$query = "UPDATE book SET smallISBN=$smal lisbn, Title='$title', Author='$author ', Publisher='$pub lisher', pages=$pages, type='$type' WHERE ISBN=$isbn";
mysql_query($qu ery) or die("Unable to execute query: " . mysqli_error($D BConnect));
}
echo $completeurl;
mysqli_close($D BConnect);
?>
</body>
</html>
<head>
<title>Run to Load Database</title>
</head>
<body>
<?php
$DBConnect = mysqli_connect( "localhost","ro ot","mysql") or die('Could not connect: ' . mysqli_error()) ;
/*mysqli_query($ DBConnect, "CREATE DATABASE library") or die("Unable to execute query: " . mysqli_error($D BConnect));*/
mysqli_select_d b($DBConnect, "library") or die ('Could not get database: ' . mysqli_error($D BConnect));
/*$query = "CREATE TABLE book (ISBN, smallISBN, Title VARCHAR(1000), Author VARCHAR(1000), Publisher VARCHAR(1000), pages)";
mysql_query($DB Connect, $query);*/
$query = "SELECT ISBN FROM book WHERE smallISBN=0";
$result = mysqli_query($D BConnect, $query) or die ('Could not query: ' . mysqli_error($D BConnect));
while($row = mysqli_fetch_ar ray($result))
{
$isbn = $row['ISBN'];
$completeurl = "http://ecs.amazonaws.c om/onca/xml?Service=AWS ECommerceServic e&AssociateTag= AKIAIYMXQSE3WJJ K5CHA&AWSAccess KeyId=MY_KEY&Op eration=ItemSea rch&SearchIndex =Books&Response Group=ItemAttri butes&Keywords= " .$isbn;
$completeurl2 = "http://isbndb.com/api/books.xml?acces s_key=My_KEY&in dex1=isbn&value 1=" .$isbn;
$xml = simplexml_load_ file($completeu rl) or die ("no file loaded");
$xml2 = simplexml_load_ file($completeu rl2) or die ("no file loaded2");
$smallisbn = $xml->Items->Item->ItemAttribut es->ISBN;
$title = addslashes($xml->Items->Item->ItemAttribut es->Title);
$titleLong = addslashes($xml 2->BookList[0]->BookData[0]->TitleLong);
$author = addslashes($xml 2->BookList[0]->BookData[0]->AuthorsText) ;
$publisher = addslashes($xml->Items->Item->ItemAttribut es->Publisher);
$publisher .= ", ";
$publisher .= $xml->Items->Item->ItemAttribut es->PublicationDat e;
$publisher .= ", ";
$publisher .= $xml->Items->Item->ItemAttribut es->Edition;
$publisher .= " Edition";
$dewey = $xml->Items->Item->ItemAttribut es->DeweyDecimalNu mber;
$pages = $xml->Items->Item->ItemAttribut es->NumberOfPage s;
$type = $xml->Items->Item->ItemAttribut es->Binding;
echo $isbn . " " . $smallisbn . " " . $title . " " . $author . " " . $publisher . " " . $pages . " " . $type . " " . $edition . " " . $publishdate;
$query = "UPDATE book SET smallISBN=$smal lisbn, Title='$title', Author='$author ', Publisher='$pub lisher', pages=$pages, type='$type' WHERE ISBN=$isbn";
mysql_query($qu ery) or die("Unable to execute query: " . mysqli_error($D BConnect));
}
echo $completeurl;
mysqli_close($D BConnect);
?>
</body>
</html>
Comment