0

我正在尝试将 SimplePie RSS 解析器配置为将提要缓存到 mySQL 数据库中,但是当我尝试加载 SimplePie 页面时,我不断收到以下错误消息:

  • 致命错误:在非对象上调用成员函数 set_cache_location()
  • 警告:substr() 期望参数 1 是字符串,数组在
  • 警告:PDO::__construct() 期望参数 2 是字符串,给定数组

当我将“端口”设置为“端口”时,我收到以下错误消息:

警告:mysql://“它在此处显示我的数据库用户名和密码”不可写。确保您设置了正确的相对或绝对路径,并且该位置是服务器可写的。在 /home/...../SimplePie.php 第 1357 行

有没有人熟悉 SimplePie?

编辑

在下面的代码中,我显然遗漏了 mySQL 设置的用户名和密码。但我只是想承认我“知道”我应该替换这些价值观。另外,我使用“3306”作为我的端口号,因为我被告知这是 mysql 的默认端口号......和主机名的“localhost”

$feed->set_cache_location('mysql://username:password@localhost:3306/database');

<?php

include('./base.php');
require_once('./php/autoloader.php');

$feed = new SimplePie();
$feed->set_cache_location('mysql://username:password@hostname:3306/database');

$rssurl = $_GET['r'];
$feedlimit = $_GET['limit'];

if (!empty($feedlimit)) {
$feedlimit = $_GET['limit'];
}

else {

$feedlimit = 10;

}

// Set which feed to process.
if (!empty($rssurl)) {

    $feed->set_feed_url($rssurl);

}

else 

    $rss_results = mysql_query("SELECT feed_id, feed_url, feed_title, feed_order, feed_page_id FROM user_feeds  WHERE ((feed_owner = '" . $_SESSION['UserId'] . "') AND (feed_page_id = '" . $pageid . "')) ORDER BY feed_order ASC LIMIT 1;");

        if ($rss_results) {

        while($row = mysql_fetch_array($rss_results))
        {
        $feed->set_feed_url($row[feed_url]);

        }

        }
        else {
          // something went wrong.
          echo mysql_error();
}



$feed->enable_cache(true);

// Run SimplePie.
$feed->init();

// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();

// Let's begin our XHTML webpage code.  The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag.
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Feed Page</title>
<script type="text/javascript" src="./js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="./js/jquery-ui-1.7.1.custom.min.js"></script>
<link rel='stylesheet' href='./css/styleb.css' type='text/css' media='all' />

<script type="text/javascript">
  // When the document is ready set up our sortable with it's inherant function(s)
  $(document).ready(function() {
    $("#test-list").sortable({
      handle : '.handle',
      update : function () {
          var order = $('#test-list').sortable('serialize');
        $("#info").load("process-sortable.php?"+order);
      }
    });
});
</script>


</head>
<body>


<div>                       






<div id="rsscontent">   

<ul>

    <?php
    /*
    Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    */
    foreach ($feed->get_items(0,$feedlimit) as $item):

        $feeditem = $item->get_feed();
    ?>
<?php if($_GET["view"] === "headlines") {

        echo "<li><h2 class='feed_entry_title'><a href='";
        echo $item->get_permalink();
        echo "'>";      
        echo $item->get_title();
        echo "</a></h2>";
        echo "<hr /></li>";

        }

elseif ($_GET["view"] === "excerpts") { 

        echo "<li><h2 class='feed_entry_title'><a href='";
        echo $item->get_permalink();
        echo "'>";
        echo $item->get_title();
        echo "</a></h2><div class='feed_entry_content'>";
        echo $item->get_description();
        echo "</div><hr /></li>";

} else { 

        echo "<li><h2 class='feed_entry_title'><a href='";
        echo $item->get_permalink();
        echo "'>";
        echo $item->get_title();
        echo "</a></h2><div class='feed_entry_content'>";
        echo $item->get_content();
        echo "</div><hr /></li>";


} ?>

    <?php endforeach; ?>
 <ul>
</div>

</body>


</html>
4

1 回答 1

2

我浏览了 php 代码,发现问题出在 MySQL.php 中。

作为快速修复,只需在 Cache 目录(第 90-94 行)中注释掉 MySQL.php:

public function __construct($location, $name, $type)
{
    $this->options = array(
          //'user' => null,
          //'pass' => null,
          //'host' => '127.0.0.1',
          //'port' => '3306',
          //'path' => '',
          'extras' => array(
                'prefix' => '',
          ),
    );
    $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));

然后它应该工作。

于 2012-09-18T17:46:33.860 回答