10/06/11 13:32
D@vide
Ho cominciato da poco lo studio di SimpleXML, con la speranza di abbandonare DOM.
Ora ho provato a riscrivere un piccolo script PHP che permette di generare un feed Atom dal database.
Il problema che riscontro è il lancio di un eccezione "Fatal error: Call to a member function addChild() on a non-object in /membri/prog/feed.php on line 16" ma non riesco a capire dove sbaglio.
Posto qui sotto il codice.
Grazie in anticipo
Ora ho provato a riscrivere un piccolo script PHP che permette di generare un feed Atom dal database.
Il problema che riscontro è il lancio di un eccezione "Fatal error: Call to a member function addChild() on a non-object in /membri/prog/feed.php on line 16" ma non riesco a capire dove sbaglio.
Posto qui sotto il codice.
<?php include_once dirname(__FILE__)."/settings.php"; $feedType = $_GET["type"]; if(isset($feedType)) { $connection = mysqli_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DATABASENAME); if(empty($connection)) die(MYSQL_ERRORMSG); if($feedType == "atom") { $xml = simplexml_load_string("<?xml version=\"1.0\" encoding=\"utf-8\"?\>"); $feed = $xml->addChild("feed"); $feed->addAttribute("xmlns", "http://www.w3.org/2005/Atom"); $feed->addChild("title", "Il Programmatore - Blog"); $link = $feed->addChild("link"); $link->addAttribute("href", "http://lol"); $feed->addChild("updated", "2003-12-13T18:30:02Z"); $author = $feed->addChild("author"); $author->addChild("name", "Riva Davide"); $stmt = $connection->prepare("SELECT title, author, date, description FROM article"); $stmt->execute(); $stmt->bind_result($title, $author, $date, $description); while($stmt->fetch()) { $item = $feed->addChild("entry"); $item->addChild("title", $title); $link = $item->addChild("link"); $link->addAttribute("href", "http://lololol/".$title); $item->addChild("updated", $date); $item->addChild("summary", $description); } echo $xml->asXML(); } mysqli_close($connection); } ?>
Grazie in anticipo
aaa