Aggress Posted July 23, 2007 Share Posted July 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 23, 2007 Share Posted July 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 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? Quote Link to comment Share on other sites More sharing options...
Aggress Posted July 23, 2007 Author Share Posted July 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
Aggress Posted July 23, 2007 Author Share Posted July 23, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 23, 2007 Share Posted July 23, 2007 Could you post your php.ini here. NOTE please attach the php.ini dont copy and paste the contents. Also remove any username/passwords you have added to the php.ini Quote Link to comment Share on other sites More sharing options...
Aggress Posted July 23, 2007 Author Share Posted July 23, 2007 Ini attached Thanks [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Aggress Posted July 24, 2007 Author Share Posted July 24, 2007 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? Quote Link to comment Share on other sites More sharing options...
Aggress Posted July 24, 2007 Author Share Posted July 24, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.