Jump to content

[SOLVED] PHP to mysql connect strangeness


Aggress

Recommended Posts

 

Hi,

 

I've got a strange issue with php to mysql connectivity, firstly some versions

 

Debian Etch

PHP 5.2.0-8+etch4

Apache 2.2.3

Mysql 5.0.32

 

- I've got a mysql user which is valid, I can log in via the command line using that user's credentials

- the mysql module for php is loaded correctly, I can view it happily through a phpinfo page

- Apache is running, Mysql is running, no errors or issues

- Using a very simple php page, I'm unable to connect to the mysql db using the verified credentials

- The error as pasted in below reports root trying to connect with no password, when the user was specified in the test page

- Mysql log reports root attempting to connect using no password

 

 

Test page code

 

<?php

mysql_connect("localhost", "user1", "mypassword") or die(mysql_error());

echo "Connected to MySQL<br />";

?>

 

Error

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /var/www/test3.php on line 2

Access denied for user 'root'@'localhost' (using password: NO)

 

MySQL Log

 

070723 18:46:07      79 Connect    Access denied for user 'root'@'localhost' (using password: NO)

 

 

I suspect for some reason what i've got in the test page is being ignored and possibly something in one of the .ini's is trying to be used, hence it reporting a failed root login, instead of user1 but even hardcoding the root password in those - for testing purposes only - hasn't made one iota of difference.    Unless I'm doing something incredibly Doh, can someone suggest why this is causing me such an annoying holdup?

 

Thanks in advance

 

Rich

 

 

Link to comment
Share on other sites

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /var/www/test3.php on line 2

Access denied for user 'root'@'localhost' (using password: NO)

 

Using Password, you have it setup to no password needed, but you supply it

Link to comment
Share on other sites

Hmm... this is a strange one. Any peramters passed to mysql_connect should everide any defaults setup in any of the ini's.

 

Try setting up your user as the default mysql user in your php.ini, restart apache and call mysql_connect() without any arguments.

 

What happens?

Link to comment
Share on other sites

 

cooldude832 on that rationale if I don't pass it a password it should work?  ie

 

<?php

mysql_connect("127.0.0.1", "user1","") or die(mysql_error());

echo "Connected to MySQL<br />";

?>

 

Tried that, doesn't make any difference.  Given i'm passing it the user called user1 why would it be coming back saying root has attempted a log in - root'@'localhost'

 

Thanks

 

Rich

Link to comment
Share on other sites

 

Ok i've also tried setting the default user and pass in the php.ini, amended my mysql connect as per follows

 

<?php

mysql_connect() or die(mysql_error());

echo "Connected to MySQL<br />";

?>

 

 

absolutely no difference. 

*Aggress pulls another clump of hair out of head

Link to comment
Share on other sites

 

If I clear my mysql root password, and ensure mysql_connect has no parameters passed it works fine.  If i have a root password set and pass it the user and pass it fails, I can verify however that this password is correct, i've checked it like 10 times.  I've also tried this with another created user, same issue.

 

For some reason the connect fails when a there's a defined user and pass, but like why?

Link to comment
Share on other sites

 

How incredibly annoying.

 

That ver of php5 ships with sql.safe_mode turned on by default

 

Thanks, either mr php developer or mr debian packager for that one.

 

But seriously, thanks to those who tried to assit

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.