query issue

query issue

am 27.09.2007 03:29:17 von Chenky

I've been trying to nut this error out for the last three days to no
success. Here's the code:

$usern = "myusername";
$passw = "mypassword";
$db="mydatabase";


$link2 = @mysql_connect("localhost", $usern, $passw);
if (! $link2) {
die("Connect error.");


}


mysql_select_db($db) or die("DB Select error");

$status = mysql_query("SELECT * FROM members WHERE usern='$user'");


while ($display = mysql_fetch_array($status)) {


print $display['usern'];



}


mysql_close($link2);

(Obviously Ive change the real database name, user and password, but
rest assured the real ones are correct - this i have triple and
quadruple checked)


On a whim I changed the $status variable to:
$status = mysql_query("SELECT * FROM members WHERE usern='$user'") or
die (mysql_error());
and was given this error:


Access denied for user 'myusername@localhost' (Using password: NO)


This is what confuses me - why isn't it recognising the use of
password? All help appreciated.

Re: query issue

am 27.09.2007 05:52:20 von Jerry Stuckle

Chenky wrote:
> I've been trying to nut this error out for the last three days to no
> success. Here's the code:
>
> $usern = "myusername";
> $passw = "mypassword";
> $db="mydatabase";
>
>
> $link2 = @mysql_connect("localhost", $usern, $passw);
> if (! $link2) {
> die("Connect error.");
>
>
> }
>
>
> mysql_select_db($db) or die("DB Select error");
>
> $status = mysql_query("SELECT * FROM members WHERE usern='$user'");
>
>
> while ($display = mysql_fetch_array($status)) {
>
>
> print $display['usern'];
>
>
>
> }
>
>
> mysql_close($link2);
>
> (Obviously Ive change the real database name, user and password, but
> rest assured the real ones are correct - this i have triple and
> quadruple checked)
>
>
> On a whim I changed the $status variable to:
> $status = mysql_query("SELECT * FROM members WHERE usern='$user'") or
> die (mysql_error());
> and was given this error:
>
>
> Access denied for user 'myusername@localhost' (Using password: NO)
>
>
> This is what confuses me - why isn't it recognising the use of
> password? All help appreciated.
>

You're using the wrong userid/password combination.

Talk to your host to see what the should be.

Of, if it's your own server, set the permissions in MySQL correctly,

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: query issue

am 27.09.2007 09:03:08 von Chenky

Like i said before, I've double triple quadruple checked all that.
Other mysql operations are conducted using exactly the same parametres
no issues at all.

Any further help appreciated.

Re: query issue

am 27.09.2007 11:50:15 von Courtney

Chenky wrote:
> Like i said before, I've double triple quadruple checked all that.
> Other mysql operations are conducted using exactly the same parametres
> no issues at all.
>
> Any further help appreciated.
>
Hmm. It may be that there is an internal variable called $user somewhere
else..

Try echoing the $query string and pasting it into a terminal session
running mysql on th server itself.

That's how I fix most issues like that.

Re: query issue

am 27.09.2007 14:49:10 von Jerry Stuckle

Chenky wrote:
> Like i said before, I've double triple quadruple checked all that.
> Other mysql operations are conducted using exactly the same parametres
> no issues at all.
>
> Any further help appreciated.
>

Access denied for user 'myusername@localhost' (Using password: NO)

This doesn't lie. You are attempting to log in as myusername@localhost,
and your password field is blank or missing.

echo $passw just before you issue the connect and see what it says.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: query issue

am 28.09.2007 03:53:22 von Chenky

The plot thickens. The problem isn't on the connect - thats all fine.
Its the actual query. I echoed the $passw and that was as expected.
It's not until the query with the die() added to it that that error
shows up.

Just as a note as an experiment, i did a mysql_num_rows query on the
$status before the while loop - it returned '1'. So its able to
execute that query. It's the while loop that was originally
encountering the problem. Then I tested the $status with a die() and
it comes up with the error.

My fundamental confusion: it dies with no password recognised, but
performed the num_rows query?!

Re: query issue

am 28.09.2007 05:25:35 von Jerry Stuckle

Chenky wrote:
> The plot thickens. The problem isn't on the connect - thats all fine.
> Its the actual query. I echoed the $passw and that was as expected.
> It's not until the query with the die() added to it that that error
> shows up.
>
> Just as a note as an experiment, i did a mysql_num_rows query on the
> $status before the while loop - it returned '1'. So its able to
> execute that query. It's the while loop that was originally
> encountering the problem. Then I tested the $status with a die() and
> it comes up with the error.
>
> My fundamental confusion: it dies with no password recognised, but
> performed the num_rows query?!
>

Then there's more to it than the code you showed us indicates.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: query issue

am 28.09.2007 05:50:41 von Courtney

Chenky wrote:
> The plot thickens. The problem isn't on the connect - thats all fine.
> Its the actual query. I echoed the $passw and that was as expected.
> It's not until the query with the die() added to it that that error
> shows up.
>
> Just as a note as an experiment, i did a mysql_num_rows query on the
> $status before the while loop - it returned '1'. So its able to
> execute that query. It's the while loop that was originally
> encountering the problem. Then I tested the $status with a die() and
> it comes up with the error.
>
> My fundamental confusion: it dies with no password recognised, but
> performed the num_rows query?!
>

Mmm.

I suspect a subtle interaction deep in the PHP-MYSQL stuff.

Don't stop. You may have found if not a bug, something worth documenting.

Re: query issue

am 29.09.2007 09:01:47 von bob.chatman

On Sep 27, 8:25 pm, Jerry Stuckle wrote:
> Chenky wrote:
> > The plot thickens. The problem isn't on the connect - thats all fine.
> > Its the actual query. I echoed the $passw and that was as expected.
> > It's not until the query with the die() added to it that that error
> > shows up.
>
> > Just as a note as an experiment, i did a mysql_num_rows query on the
> > $status before the while loop - it returned '1'. So its able to
> > execute that query. It's the while loop that was originally
> > encountering the problem. Then I tested the $status with a die() and
> > it comes up with the error.
>
> > My fundamental confusion: it dies with no password recognised, but
> > performed the num_rows query?!
>
> Then there's more to it than the code you showed us indicates.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I've been using mysql functions for years and ive never seen this sort
of willy nilly craziness. Either one of two things are happening...

1) Jerry is completely correct and this is absurd
2) PHP has a bug in its mysql connection which has never been
experienced before.

Either we need to see some proper output or this is a moot discusion,
as it wont do us any good to speculate on the meaning of what has been
posted because its not code, and hear-say is meaningless.