p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: connecting to mysql p.402


Message #1 by "Art Stoller" <phphelp@w...> on Wed, 2 Oct 2002 15:09:13
I am stuck on trying to connect to mysql server via php as per p.402 
beginning php
Can you help?
Here is the php script and the returned error messages:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<?php
	//listing databases
	$link_id=mysql_connect("localhost", "phpuser", "phppass");
	$result = mysql_list_dbs($link_id);
	$num_rows=mysql_num_rows($result);
	
	while($db_data=mysql_fetch_row($result)){
		echo $db_data[0]. "<br>";
		$result2=mysql_list_tables($db_data[0]);
		$num_rows2=mysql_num_rows($result2);
		while($table_data=mysql_fetch_row($result2)) echo "==" . 
$table_data[0]. "<br>";
		echo "==>$num_rows2 table(s) in " . $db_data[0] . "<p>";
		}
		?>
		
</body>
</html>



Warning: Access denied for user: '-u@l...' (Using password: YES) in 
c:\program files\easyphp\www\phpuser.php on line 11

Warning: MySQL Connection Failed: Access denied for user: '-u@l...' 
(Using password: YES) in c:\program files\easyphp\www\phpuser.php on line 
11

Warning: mysql_list_dbs(): supplied argument is not a valid MySQL-Link 
resource in c:\program files\easyphp\www\phpuser.php on line 12

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result 
resource in c:\program files\easyphp\www\phpuser.php on line 13

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result 
resource in c:\program files\easyphp\www\phpuser.php on line 15




Message #2 by "Gellings, C.O." <gellingsco@p...> on Wed, 2 Oct 2002 17:09:24 +0200
In your while loop you make use of a fetch_array function. Try the
fetch_object function instead:

	$link_id=mysql_connect("localhost", "phpuser", "phppass");
	while($db_data=mysql_fetch_object($result)){
		echo $db_data -> Database . '\n';
	}

-----Original Message-----
From: Art Stoller [mailto:phphelp@w...]
Sent: 02 October 2002 15:09
To: beginning php
Subject: [beginning_php] connecting to mysql p.402


I am stuck on trying to connect to mysql server via php as per p.402
beginning php
Can you help?
Here is the php script and the returned error messages:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<?php
	//listing databases
	$link_id=mysql_connect("localhost", "phpuser", "phppass");
	$result = mysql_list_dbs($link_id);
	$num_rows=mysql_num_rows($result);

	while($db_data=mysql_fetch_row($result)){
		echo $db_data[0]. "<br>";
		$result2=mysql_list_tables($db_data[0]);
		$num_rows2=mysql_num_rows($result2);
		while($table_data=mysql_fetch_row($result2)) echo "==" .
$table_data[0]. "<br>";
		echo "==>$num_rows2 table(s) in " . $db_data[0] . "<p>";
		}
		?>

</body>
</html>



Warning: Access denied for user: '-u@l...' (Using password: YES) in
c:\program files\easyphp\www\phpuser.php on line 11

Warning: MySQL Connection Failed: Access denied for user: '-u@l...'
(Using password: YES) in c:\program files\easyphp\www\phpuser.php on line
11

Warning: mysql_list_dbs(): supplied argument is not a valid MySQL-Link
resource in c:\program files\easyphp\www\phpuser.php on line 12

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in c:\program files\easyphp\www\phpuser.php on line 13

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result
resource in c:\program files\easyphp\www\phpuser.php on line 15





Message #3 by "Nikolai Devereaux" <yomama@u...> on Wed, 2 Oct 2002 09:28:41 -0700
Sounds like you aren't connecting to mysql with the correct username and/or
password.

If you add a new username to mysql's user table, you have to reload mysql for
those tables to be reprocessed before those new username/password combos will
be accepted.


nik

Message #4 by "KayKay-GG \(E-mail\)" <kaykay@g...> on Wed, 2 Oct 2002 23:12:24 +0530
Try connecting using the command line first and verify your auth. details..
then look at your script.

-K

>>>>-----Original Message-----
>>>>From: Art Stoller [mailto:phphelp@w...]
>>>>Sent: 02 October 2002 15:09
>>>>To: beginning php
>>>>Subject: [beginning_php] connecting to mysql p.402
>>>>
>>>>
>>>>I am stuck on trying to connect to mysql server via php as
>>>>per p.402
>>>>beginning php
>>>>Can you help?
>>>>Here is the php script and the returned error messages:
>>>>
>>>>
>>>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
>>>>
>>>><html>
>>>><head>
>>>>	<title>Untitled</title>
>>>></head>
>>>>
>>>><body>
>>>><?php
>>>>	//listing databases
>>>>	$link_id=mysql_connect("localhost", "phpuser", "phppass");
>>>>	$result = mysql_list_dbs($link_id);
>>>>	$num_rows=mysql_num_rows($result);
>>>>
>>>>	while($db_data=mysql_fetch_row($result)){
>>>>		echo $db_data[0]. "<br>";
>>>>		$result2=mysql_list_tables($db_data[0]);
>>>>		$num_rows2=mysql_num_rows($result2);
>>>>		while($table_data=mysql_fetch_row($result2))
>>>>echo "==" .
>>>>$table_data[0]. "<br>";
>>>>		echo "==>$num_rows2 table(s) in " . $db_data[0] . "<p>";
>>>>		}
>>>>		?>
>>>>
>>>></body>
>>>></html>
>>>>
>>>>
>>>>
>>>>Warning: Access denied for user: '-u@l...' (Using
>>>>password: YES) in
>>>>c:\program files\easyphp\www\phpuser.php on line 11
>>>>
>>>>Warning: MySQL Connection Failed: Access denied for user:
>>>>'-u@l...'
>>>>(Using password: YES) in c:\program
>>>>files\easyphp\www\phpuser.php on line
>>>>11
>>>>
>>>>Warning: mysql_list_dbs(): supplied argument is not a valid
>>>>MySQL-Link
>>>>resource in c:\program files\easyphp\www\phpuser.php on line 12
>>>>
>>>>Warning: mysql_num_rows(): supplied argument is not a valid
>>>>MySQL result
>>>>resource in c:\program files\easyphp\www\phpuser.php on line 13
>>>>
>>>>Warning: mysql_fetch_row(): supplied argument is not a
>>>>valid MySQL result
>>>>resource in c:\program files\easyphp\www\phpuser.php on line 15



Message #5 by "Art Stoller" <phphelp@w...> on Wed, 2 Oct 2002 21:00:01
I reloaded mysql and checked the username and password from the command 
line.
userphp exists in the user table.

password is an encryption I think, of ?phppass? also in the user table and 
still get the error messages below:


So I run my browser again on phpuser.php 
<html>
<head>
	<title>Untitled</title>
</head>

<body>
<?php
	//listing databases
	$link_id=mysql_connect("localhost", "phpuser", "phppass");
	$result = mysql_list_dbs($link_id);
	$num_rows=mysql_num_rows($result);
	
	while($db_data=mysql_fetch_row($result)){
		echo $db_data[0]. "<br>";
		$result2=mysql_list_tables($db_data[0]);
		$num_rows2=mysql_num_rows($result2);
		while($table_data=mysql_fetch_row($result2)) echo "==" . 
$table_data[0]. "<br>";
		echo "==>$num_rows2 table(s) in " . $db_data[0] . "<p>";
		}
		?>
		
</body>

Warning: Access denied for user: 'phpuser@l...' (Using password: YES) 
in c:\program files\easyphp\www\phpuser.php on line 11

Warning: MySQL Connection Failed: Access denied for 
user: 'phpuser@l...' (Using password: YES) in c:\program 
files\easyphp\www\phpuser.php on line 11

Warning: mysql_list_dbs(): supplied argument is not a valid MySQL-Link 
resource in c:\program files\easyphp\www\phpuser.php on line 12

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result 
resource in c:\program files\easyphp\www\phpuser.php on line 13

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result 
resource in c:\program files\easyphp\www\phpuser.php on line 15
Message #6 by "Nikolai Devereaux" <yomama@u...> on Wed, 2 Oct 2002 13:00:03 -0700
> userphp exists in the user table.

Is this a typo?  You're connecting with "phpuser", not "userphp".

Message #7 by CathyV227@a... on Wed, 2 Oct 2002 22:21:26 EDT
?????????? 

Message #8 by CathyV227@a... on Wed, 2 Oct 2002 22:25:35 EDT
explain please

Message #9 by "Nikolai Devereaux" <yomama@u...> on Wed, 2 Oct 2002 19:46:32 -0700
Okay, pardon the upcoming rant... BUT the past two posts on this thread have to
be among the most vague and irritating type of post that can be on a mailing
list.

There have been several posts on this thread already, and to have two
consecutive posts, "??????????" and "explain please", added to the thread does
nobody any good.

You might want to be a bit more clear with your question -- what part, exactly,
did you not understand?


Art Stoller had problems connecting to his database.  A couple people offered
suggestions.  I haven't heard a reply from Art whether or not our suggestions
helped him solve his problem or not.

So what's up with the "??????????"??????????

explain please

Message #10 by "Tonsil" <tonsil@s...> on Thu, 3 Oct 2002 00:17:01 -0400
All I can say is "AOL".

_________________________________________________
This email has been brought to you by:
     House Arrest Daycare (tm)
"Hey, I figgered I wasn't goin' nowhere nohow..."
Message #11 by "Art Stoller" <phphelp@w...> on Thu, 3 Oct 2002 15:23:30
I still can?t connect to database.
Here is the database and table and fields set up
(from going in at the command line in mysql)

Database	Table	Host		User		Password
mysql		user	localhost	root		123 encrypted
mysql		user	localhost	phpuser	phppass

I run the php code in earlier postings and get error results as in earlier 
postings.
What am I doing wrong?

Arthur
Message #12 by "Art Stoller" <phphelp@w...> on Thu, 3 Oct 2002 15:26:24
Sorry, here is a reformatted question:

I still can?t connect to database.
H> ere is the database and table and fields set up
(> from going in at the command line in mysql)

Database  Table	Host		User		Password
mysql	  user	localhost	root		123 (encrypted)
mysql	  user	localhost	phpuser	        phppass (encrypted)

I run the php code in earlier postings and get error results as in earlier 
postings.
What am I doing wrong?

> Arthur
Message #13 by "Nikolai Devereaux" <yomama@u...> on Thu, 3 Oct 2002 11:04:02 -0700
> I still can?t connect to database.
> Here is the database and table and fields set up
> (from going in at the command line in mysql)
>
> Database  Table Host       User    Password
> mysql     user  localhost  root    123 (encrypted)
> mysql     user  localhost  phpuser phppass (encrypted)
>
> I run the php code in earlier postings and get error
> results as in earlier postings.
> What am I doing wrong?


More questions:

*  How did you encrypt your password?

You must encrypt your password using the PASSWORD() function in mysql.  If you
encrypted your password using any other encryption function, then your login
will fail because the hashes will not match.

Related links:
  http://www.mysql.com/doc/en/User_names.html
  http://www.mysql.com/doc/en/Miscellaneous_functions.html


*  Can you connect successfully as root?

I want to verify that you can connect to the server at all.


take care,

nik


Message #14 by "Art Stoller" <phphelp@w...> on Fri, 4 Oct 2002 15:01:08
> > I still can?t connect to database.
> Here is the database and table and fields set up
> (from going in at the command line in mysql)
>
> Database  Table Host       User    Password
> mysql     user  localhost  root    123 (encrypted)
> mysql     user  localhost  phpuser phppass (encrypted)
>
> I run the php code in earlier postings and get error
> results as in earlier postings.
> What am I doing wrong?


More questions:

*  How did you encrypt your password?

You must encrypt your password using the PASSWORD() function in mysql.  If 
you
encrypted your password using any other encryption function, then your 
login
will fail because the hashes will not match.

Related links:
  http://www.mysql.com/doc/en/User_names.html
  http://www.mysql.com/doc/en/Miscellaneous_functions.html


*  Can you connect successfully as root?

I want to verify that you can connect to the server at all.


take care,

nik


Message #15 by "Art Stoller" <phphelp@w...> on Fri, 4 Oct 2002 15:02:42

I can connect sussessfully as root but when I change to phpuser and 
phppass I get a series of error messages which may mean I cam not connectd.

Art
Message #16 by "Nikolai Devereaux" <yomama@u...> on Fri, 4 Oct 2002 12:51:44 -0700
Again, how did you encrypt the password for phpuser?


I just took three minutes or so to do this:

INSERT INTO `user`
            (`Host`, `User`, `Password`,
             `Select_priv`, `Insert_priv`,
             `Update_priv`, `Delete_priv`)
     VALUES ('localhost', 'phpuser', PASSWORD('phppass'),
             'Y', 'Y', 'Y', 'Y');


reload mysql


<?php

mysql_connect('localhost', 'phpuser', 'phppass');
mysql_select_db('test');
$result = mysql_query('SELECT * FROM table1');

echo '<pre>';
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
   print_r($row);
}
echo '</pre>';
?>



it worked fine...


  Return to Index