Jump to content

simplexml_load_file can't load URL


HardlyWorking

Recommended Posts

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:

Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\Program Files\EasyPHP 3.0\www\loadDatabase.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","root","mysql") or die('Could not connect: ' . mysqli_error());

 

/*mysqli_query($DBConnect, "CREATE DATABASE library") or die("Unable to execute query: " . mysqli_error($DBConnect));*/

 

mysqli_select_db($DBConnect, "library") or die ('Could not get database: ' . mysqli_error($DBConnect));

 

/*$query = "CREATE TABLE book (ISBN, smallISBN, Title VARCHAR(1000), Author VARCHAR(1000), Publisher VARCHAR(1000), pages)";

mysql_query($DBConnect, $query);*/

 

$query  = "SELECT ISBN FROM book WHERE smallISBN=0";

$result = mysqli_query($DBConnect, $query) or die ('Could not query: ' . mysqli_error($DBConnect));

 

while($row = mysqli_fetch_array($result))

{

$isbn = $row['ISBN'];

    $completeurl = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AssociateTag=AKIAIYMXQSE3WJJK5CHA&AWSAccessKeyId=MY_KEY&Operation=ItemSearch&SearchIndex=Books&ResponseGroup=ItemAttributes&Keywords=" .$isbn; 

 

  $completeurl2 = "http://isbndb.com/api/books.xml?access_key=My_KEY&index1=isbn&value1=" .$isbn;

 

  $xml = simplexml_load_file($completeurl) or die ("no file loaded");

  $xml2 = simplexml_load_file($completeurl2) or die ("no file loaded2");

 

    $smallisbn = $xml->Items->Item->ItemAttributes->ISBN;

$title = addslashes($xml->Items->Item->ItemAttributes->Title);

$titleLong = addslashes($xml2->BookList[0]->BookData[0]->TitleLong);

$author = addslashes($xml2->BookList[0]->BookData[0]->AuthorsText);

$publisher = addslashes($xml->Items->Item->ItemAttributes->Publisher);

$publisher .= ", ";

$publisher .= $xml->Items->Item->ItemAttributes->PublicationDate;

$publisher .= ", ";

$publisher .= $xml->Items->Item->ItemAttributes->Edition;

$publisher .= " Edition";

$dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;

$pages = $xml->Items->Item->ItemAttributes->NumberOfPages;

$type = $xml->Items->Item->ItemAttributes->Binding;

 

echo $isbn . " " . $smallisbn . " " . $title . " " . $author . " " . $publisher . " " . $pages . " " . $type . " " . $edition . " " . $publishdate;

 

$query = "UPDATE book SET smallISBN=$smallisbn, Title='$title', Author='$author', Publisher='$publisher', pages=$pages, type='$type' WHERE ISBN=$isbn";

    mysql_query($query) or die("Unable to execute query: " . mysqli_error($DBConnect));

 

   

}

 

 

echo $completeurl;

mysqli_close($DBConnect);

?>

 

 

 

 

</body>

</html>

 

Any ideas appreciated.

Link to comment
https://forums.phpfreaks.com/topic/167702-simplexml_load_file-cant-load-url/
Share on other sites

Perhaps there is something wrong with my php, but I get

"Fatal error: Call to undefined function getaddrinfo() " if I run it from a server and

"Could not open input file" if I run it from the command line.

 

I am on a proxy network; perhaps that is the problem?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.