HardlyWorking Posted July 27, 2009 Share Posted July 27, 2009 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 More sharing options...
ldougherty Posted July 28, 2009 Share Posted July 28, 2009 The script is failing on converting the hostname to an IP address it seems. Try using the getaddrinfo() function from the DOS prompt to see if you can do this manually outside of the script. http://msdn.microsoft.com/en-us/library/ms738520(VS.85).aspx Link to comment https://forums.phpfreaks.com/topic/167702-simplexml_load_file-cant-load-url/#findComment-884422 Share on other sites More sharing options...
HardlyWorking Posted July 28, 2009 Author Share Posted July 28, 2009 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? Link to comment https://forums.phpfreaks.com/topic/167702-simplexml_load_file-cant-load-url/#findComment-884971 Share on other sites More sharing options...
aschk Posted July 28, 2009 Share Posted July 28, 2009 Perhaps you'll find that allow_url_fopen is disabled in your server PHP environment, and if you're getting an undefined function error I expect the version of PHP you're running in production is lower than what you're developing in. Link to comment https://forums.phpfreaks.com/topic/167702-simplexml_load_file-cant-load-url/#findComment-884979 Share on other sites More sharing options...
HardlyWorking Posted July 28, 2009 Author Share Posted July 28, 2009 I'm using a server with PHP version 5.2.8, which I think is one of the more recent ones. Is there any way to tell what is disabled? Link to comment https://forums.phpfreaks.com/topic/167702-simplexml_load_file-cant-load-url/#findComment-884994 Share on other sites More sharing options...
HardlyWorking Posted July 28, 2009 Author Share Posted July 28, 2009 I got it fixed with a cURL workaround to the proxy server. Thanks. Link to comment https://forums.phpfreaks.com/topic/167702-simplexml_load_file-cant-load-url/#findComment-885105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.