Drupal error and solution: Access denied for user in mysqli or mysql

I have been facing this peculiar problem in drupal. I was migrating a drupal site from one server to another and it stopped working, giving me the error ‘Access denied for user ‘some_user’@localhost (using password: YES)

It was strange since i had done everything correctly and from command line i could login into mysql server.

While i was browsing the file sites/default/settings.php my eye went into the following lines:

/*
* Note that the $db_url variable gets parsed using PHP's built-in
* URL parser (i.e. using the "parse_url()" function) so make sure
* not to confuse the parser. If your username, password
* or database name contain characters used to delineate
* $db_url parts, you can escape them via URI hex encodings:
*
*   : = %3a   / = %2f   @ = %40
*   + = %2b   ( = %28   ) = %29
*   ? = %3f   = = %3d   & = %26

I was a victim of highly unpropable circumastances! lol My password contained the sequence ‘%40’ which was being considered as the escape of character ‘@’ , so my password was interpreted wrong!

I guess that this error had to do with the php version. So in my first server (Gentoo PHP 5.2.6-pl7-gentoo) there was no problem but in the second server (Debian – PHP 5.2.0-8+etch15) there was.

After i changed my password it connected successfully.

PS. It was over a year since i posted last time, so … hurray!