Ciao a tutti!
faccio riferimento alla pillola su come creare e mostrare un feed rss:
http://forum.html.it/forum/showthrea...=&pagenumber=1
Orbene...
ho seguito attentamente il tutorial...
ma nel momento in cui provi a visualizzare il feed mi compare questo messaggio di errore:
Errore interpretazione XML: contenuto illegale dopo l'elemento Indirizzo:
http://www.miosito.com/rss/rss.php Linea numero 2, colonna 1:
Warning: mysql_connect() [
function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in
/mp_2010/rss/rss.php on line
10
^
di seguito vi posto il codice che uso
Codice PHP:
<?php
header("Content-type: application/xml");
$dbhost = "localhost";
$dbname = "mydb";
$dbuser = "root";
$dbpass = "root";
$query = mysql_connect($dbhost, $dbuser, $dbpass); //la riga 10 è questa
if($query == FALSE) die ("Errore durante la connessione a mySQL ".mysql_error());
$query2 = "SELECT * FROM `news` ORDER BY `data` DESC LIMIT 7";
$risultato = mysql_query($query2, $query);
require_once("feedcreator.class.php");
$rss = new UniversalFeedCreator();
$rss->useCached();
$rss->title = "titolo";
$rss->description = "descrizione del feed";
$rss->link = "http://www.miosito.com";
$rss->feedURL = "http://miosito.com/rss/rss.php";
$rss->cssStyleSheet = "";
function xmlentities ( $string ){
$ar1 = array ('&', '"', '&apos', '<', '>' );
$ar2 = array ('&', '"', "'", '<', '>');
return str_replace ( $ar1, $ar2, $string);
}
while($data=mysql_fetch_array($risultato)){
$data['titolo'] = xmlentities($data['titolo']);
$data['testo'] = xmlentities($data['testo']);
$item = new FeedItem();
$item->title = $data['titolo'];
$item->link = "http://www.marcopolosrl.it";
$item->description = $data['testo'];
$item->category = "news";
$item->date = $data['giorno']." ".$data['mese']." ".$data['anno'];
$item->author = "info@miosito.it";
$item->descriptionHtmlSyndicated = true;
$item->categoryHtmlSyndicated = true;
$item->descriptionTruncSize = 500;
$rss->addItem($item);
}
echo $rss->createFeed("RSS2.0", ""); ?>
infine aggiungo che la classe feedcreator.class.php l'ho trovata qui http://feedcreator.org/.
Ora... la domanda è... dove ho sbagliato?