在Xml中使用PHP PDO连接数据库以获取要显示在RSS提要中的数据


Connecting DataBase using PHP PDO in Xml to Fetch Data to Show in RSS feed

 <?php
// Please note that the file is saved as rss.php and the xml code is included in it. 
// Include necessary files
include_once '../inc/function.inc.php';
include_once '../inc/db.inc.php';
// Till here no problem
// Open a database connection
$db = new PDO(DB_INFO, DB_USER, DB_PASS);
// When i connect to database I get error.
// in Internet Explorer: This feed contains code error
//in Mozila: Its pops up a rss.php and asks me to open it and save to a specific location
/in Chrome: It displays all the code as it is in the Browser 
// Load all blog entries
$e = retrieveEntries($db, 'blog');
// Remove the fulldisp flag
array_pop($e);
// Perform basic data sanitization
$e = sanitizeData($e);
// Add a content type header to ensure proper execution
header('Content-Type: application/rss+xml');
// Output the XML declaration
echo "<?xml version='"1.0'" encoding='"UTF-8'"?>'n";

?>

<rss version="2.0">
<channel>
        <title>My Simple Blog</title>
        <link>http://localhost/simple_blog/</link>
        <description>This blog is awesome.</description>
        <language>en-us</language>
        <?php
        // Loop through the entries and generate RSS items
        foreach($e as $e):
        // Escape HTML to avoid errors
        $entry = htmlentities($e['entry']);
        // Build the full URL to the entry
        $url = 'http://localhost/simple_blog/blog/' . $e['url'];
        ?>
        <item>
        <title><?php echo $e['title']; ?></title>
        <description><?php echo $entry; ?></description>
        <link><?php echo $url; ?></link>
        </item>
        <?php endforeach; ?>    
</channel>
</rss>

我已经在代码中以注释的形式解释了我所面临的问题。请告诉我连接是否正确。

我错过了一些关于代码或语法使用xml在php?

在黑暗中拍摄

请注意文件保存为rss.php

根据症状判断,要么是没有保存为rss.php,要么是服务器上没有安装PHP。