gpt4 book ai didi

php - SimplePie: fatal error :调用非对象上的成员函数 set_cache_location()

转载 作者:行者123 更新时间:2023-11-29 08:49:22 24 4
gpt4 key购买 nike

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

  • fatal error :在非对象上调用成员函数 set_cache_location()
  • 警告:substr() 期望参数 1 为字符串,数组中给出
  • 警告:PDO::__construct() 期望参数 2 为字符串,给定数组

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

Warning: mysql:// "IT DISPLAYS MY DB USERNAME AND PASSWORD HERE" is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable. in /home/...../SimplePie.php on line 1357

有人熟悉SimplePie吗?

编辑

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

$feed->set_cache_location('mysql://用户名:密码@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>

最佳答案

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

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

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));

然后它应该可以工作。

关于php - SimplePie: fatal error :调用非对象上的成员函数 set_cache_location(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11703817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com