Search code examples
phpmysqlsimplepie

SimplePie: Fatal error: Call to a member function set_cache_location() on a non-object


I'm trying to configure the SimplePie RSS parser to cache feeds into a mySQL database, but I keep getting this error messages when I try to load a SimplePie page:

  • Fatal error: Call to a member function set_cache_location() on a non-object
  • Warning: substr() expects parameter 1 to be string, array given in
  • Warning: PDO::__construct() expects parameter 2 to be string, array given

When I set "port" as "port" I get the following error message:

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

Is there anyone familar with SimplePie?

EDIT

In the code below I've obviously left out my username and password for the mySQL settings. But I just wanted to acknowledge that I "know" I'm supposed to replace those values. Also, I use "3306" as my port number since I'm told that 's the default port number for mysql...and "localhost" for the hostname

$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>

Solution

  • I have gone through the php code and found out that the problem is in MySQL.php.

    As a quick fix, just comment out MySQL.php in the Cache directory (line 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));
    

    Then it should work.