Php SimplePie:致命错误:调用非对象上的成员函数set_cache_location()
我试图将SimplePie RSS解析器配置为将提要缓存到mySQL数据库中,但在尝试加载SimplePie页面时,我不断收到以下错误消息:Php SimplePie:致命错误:调用非对象上的成员函数set_cache_location(),php,mysql,simplepie,Php,Mysql,Simplepie,我试图将SimplePie RSS解析器配置为将提要缓存到mySQL数据库中,但在尝试加载SimplePie页面时,我不断收到以下错误消息: 致命错误:调用非对象上的成员函数set_cache_location() 警告:substr()要求参数1为字符串,数组在 警告:PDO::_construct()要求参数2为字符串,数组给定 当我将“端口”设置为“端口”时,我收到以下错误消息: 警告:mysql://“此处显示我的DB用户名和密码”是 不可写。确保设置了正确的相对或绝对值 路径,并且
- 致命错误:调用非对象上的成员函数set_cache_location()
- 警告:substr()要求参数1为字符串,数组在
- 警告:PDO::_construct()要求参数2为字符串,数组给定
我浏览了php代码,发现问题出在MySQL.php中
作为快速修复,只需在缓存目录(第90-94行)中注释掉MySQL.php即可:
然后它应该可以工作。很明显,您调用函数的“对象”不是对象(未实例化)。确保它已实例化。例如:$obj=新对象()$obj->function();一些代码会有帮助,请发布您的代码。听上去,你没有在代码中正确使用set\u cache\u location()
。我已经添加了我正在使用的代码。虽然目前有文档证明它不受支持,除非你正在运行一个特定的分支,但我不确定情况是否仍然如此(它链接到他们的旧SVN存储库,而不是没有提到的分支的新SVN存储库). 因此,我建议深入研究一下,以验证您是否可以使用该功能,以及您是否拥有所需的功能。嘿,morgant,我也有同样的想法。这就是为什么我在SimplePie文件/代码中进行了深入研究……我发现了对mysql的各种引用……所以我很确定它支持它。另外,我使用的是最新版本1.3,mysql功能是在两个版本之前(实验性地)引入的。(我不认为文档已经更新了一段时间。)非常感谢你,Timothy,这非常有效。很抱歉迟了答复。在对SimplePie和StackOverflow社区(说来话长)感到非常失望之后,我放弃了这个项目。但多亏了你的帮助,我又恢复了努力。
<?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>
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));