0
<?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>
我已經在我面臨什麼問題的代碼註釋的形式解釋。如果我連接正確,請讓我知道。使用PHP PDO在XML中獲取數據的RSS,以顯示連接數據庫飼料
我是否缺少與代碼相關的內容或在php中使用xml的語法?
DB_INFO是什麼?問題的描述應該包含在問題的文本部分中,而不是作爲代碼的註釋。 – Havelock 2013-04-28 04:16:08
那些DB_INFO,DB_USER,DB_PASS)變量包含哪些內容? – 2013-04-28 04:16:37
你確定它喜歡'PDO('mysql:host = blabla; dbname = blabla',$ user,$ pass);'? – 2013-04-28 04:17:38