Page 1 of 1

"Access Denied" to database when using fetchEntrie

Posted: Thu Nov 15, 2007 4:59 am
by goodevilgenius
On my website, I'd like one of my main pages to be able to grab blog entries from a specific category, and process them. The script that fetches the entries is located in the parent directory of s9y. s9y is locate in a directory called .serendipity.
Here's the part of my code that's giving me problems:

Code: Select all

function getAllVideos() {
  chdir('.serendipity');
  include 'serendipity_config.inc.php';
  $serendipity['GET']['category'] = 'videos';
  $entries = serendipity_fetchEntries(null, true);
  chdir('..');
  return $entries;
}
When my page tries to call this function, I get the following error:

Code: Select all

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'goodevil'@'localhost' (using password: NO) in /home/goodevil/public_html/joestryker/.serendipity/include/db/mysql.inc.php on line 270
I don't get the same error when accessing the blog directly.

Has anyone seen this error before? How do I get around it?

Posted: Thu Nov 15, 2007 5:03 am
by goodevilgenius
The same problem occurs if it's in the same directory as serendipity (removing the chdir commands, of course), so it's not a problem with being in a different directory.

Posted: Thu Nov 15, 2007 6:26 am
by goodevilgenius
Ok, I figured out some more about the problem. After some digging around, I discovered that for some reason $serendipity is not visible in serendipity_db_connect() (which is where the problem occurs in mysql.inc.php), even though the first line in the function is "global $serendipity." It's also definitely visible at the top of mysql.inc.php.

The reason this is causing the problem is because the line where the error occurs reads "$serendipity['dbConn'] = $function($serendipity['dbHost'], $serendipity['dbUser'], $serendipity['dbPass']);" so it's calling mysql_connect(null,null,null).

Ok, so here's the really weird thing. I have two serendipity installations running on the same server. I tried to the same thing with the other installation, and had no problem. It ran exactly as expected, and $serendipity was visible where it should be.

So, I'm stuck. This sounds like a PHP bug, but I don't understand why it works in one place, but not in the other.

Has anybody got ANY ideas?

Posted: Thu Nov 15, 2007 9:51 am
by garvinhicking
Hi!

Try to add a "global $serendipity" to your getAllVideos() function?

Regards,
Garvin

Posted: Thu Nov 15, 2007 3:12 pm
by goodevilgenius
garvinhicking wrote:Hi!

Try to add a "global $serendipity" to your getAllVideos() function?

Regards,
Garvin
Thank you so much! That did it!