From: Jason Pruim on
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? :)
From: Jason Pruim on

On May 16, 2010, at 1:11 PM, Ashley Sheridan wrote:

> On Sun, 2010-05-16 at 13:14 -0400, Jason Pruim 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? :)
>>
>
> Are the MySQL ports open and available on both servers?

Hey Ash,

Yes they are. It's on the same machine so ports shouldn't be an issue
I would think?

>

From: Peter Lind on
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.

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>