0

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>
Richard
  • 209
  • 2
  • 10
  • Aparently the "object" you're calling the function on is not an object (not instantiated). Make sure it's instantiated. E.g.: $obj = new Object(); $obj->function(); Some code would help – Bono Jul 28 '12 at 19:07
  • Please post your code. By the sounds of it, you're not using `set_cache_location()` correctly in your code. – Ryan McCue Jul 30 '12 at 05:59
  • I have added the code I am using. – Richard Jul 30 '12 at 17:04
  • While [setting a database cache location](http://simplepie.org/wiki/reference/simplepie/set_cache_location#set_a_database_location) is currently documented as being unsupported unless you're running a specific branch, I'm not sure that's still the case (it links to their old SVN repository, not their new [GitHub repository](http://github.com/simplepie/simplepie/) which doesn't have the mentioned branch). So, I'd suggest digging into that to verify that you can use that functionality and you have what you need to do so. – morgant Jul 30 '12 at 17:50
  • Hey morgant, I had the same thought too. That why I dug around the SimplePie files/code...and I found various reference to mysql...so I'm pretty sure it supports it. Also, I'm using the latest version 1.3 and the mysql functionality was introduced (experimentally) two versions ago. (I don't think the documentation has been updated in a while.) – Richard Jul 30 '12 at 20:04
  • Can someone recommend a developer that could fix this? – Richard Jul 31 '12 at 16:52
  • @Richard Can you include the line number/file for the errors please? – Ryan McCue Aug 03 '12 at 06:37
  • When "port" equals "port" -> /SimplePie.php on line 1357 – Richard Aug 05 '12 at 22:44
  • When "port" equals 3306 - > Warning: substr() expects parameter 1 to be string, array given in .../SimplePie/Cache/MySQL.php on line 102 Warning: PDO::__construct() expects parameter 2 to be string, array given in .../SimplePie/Cache/MySQL.php on line 106 Fatal error: Call to a member function query() on a non-object in .../SimplePie/Cache/MySQL.php on line 116 – Richard Aug 05 '12 at 22:47

1 Answers1

2

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.

Gabriel Chung
  • 1,527
  • 1
  • 18
  • 30
  • Thank you very much, Timothy, this worked perfectly. Sorry for the late reply. I had abandoned this project after much frustration with the SimplePie and StackOverflow community (long story). But I've resumed my efforts thanks to your help. – Richard Dec 01 '12 at 18:17