From: Jason Pruim on

On May 16, 2010, at 1:21 PM, Peter Lind wrote:

> On 16 May 2010 19:14, Jason Pruim <lists(a)pruimphotography.com> wrote:
>> Hi Everyone!
>>
>> So I'm sitting here trying to get my RSS feed to work off of my main
>> database login script so that I can centralize the management of
>> the whole
>> blasted thing, you know... stuff like only having the password in
>> one place
>> to log into the DB :)
>>
>> I can connect just fine if I include all the connection stuff
>> locally in my
>> file, but when I try and include it so I don't have to reinvent the
>> wheel it
>> says it can't connect.... Host, Username, & Password have all been
>> checked
>> and doubled checked. And actually the database connection script
>> works just
>> fine since I'm using it to pull the content from my main page and
>> that's
>> working just fine...
>>
>>
>> Here's the code I'm using locally on the page:
>>
>> <?PHP
>> $server = "localhost";
>> $username = "realusername";
>> $password = "realpass";
>> $database = "realdatabase";
>>
>>
>> $linkID = mysql_connect($server, $username, $password) or
>> die("Could not
>> connect to host." . mysql_error());
>> mysql_select_db($database, $linkID) or die("Could not find
>> database." .
>> mysql_error($linkID));
>> ?>
>>
>> That code works...
>>
>> When I change it to:
>>
>> <?PHP
>> $linkID = dbconnect($server, $username, $password, $database) or
>> die("Could
>> not connect to host." . mysql_error());
>> ?>
>>
>>
>> with that function defined as:
>>
>> <?PHP
>> function dbconnect($server, $username, $password, $database) {
>> mysql_connect($server, $username, $password) or die("Unable to
>> connect:
>> ".mysql_error());
>>
>> mysql_select_db($database) or die("Unable to select
>> database:".mysql_error());
>>
>>
>> }
>> ?>
>>
>> that will not work on my rss feed. But it does work on my main page
>> which
>> uses the dbconnect script. The only error that I'm getting is the
>> one set in
>> my dbconnect call... "Could not connect to host".
>>
>> So can anyone see where I'm missing my comma or semicolon? :)
>
> Your dbconnect function is not returning a value, defaulting to a null
> return value. That means the or statement runs the die statement -
> even though you're connecting.

Hey Peter,

That was the problem... The reason it was working on the main page is
I didn't have a "Or die()" statement on the main page...

Now I'll be setting a return value on there so that it works for all
of them :)

Thanks for pointing out my stupidity :)