Hi

/EDIT: I should have read your post more carefully,
but I don't get the exact point where the error
appears...
...
You may check whether you have a firewall or so,
not allowing a connection to ..err.. 3306 (tcp),
even if local login.

PHP

A snippet of my code (should look similar to yours):

Code:
  #---------------------------------------------
  #SETTINGS
  $connector = "localhost";
  $login= "root";
  $password= "root";
  $dbname= "gallery";
  #---------------------------------------------

$db = mysql_connect($connector,$login,$password);

  if ($db == false){
      print "<p>myERROR: Connection to MySQL-Server failed.</p>\n";
      exit;
  }

  #CONNECT TO DB

  $result = mysql_select_db($dbname,$db); 
  if ($result == false){
      print "<p>myERROR: $dbname does not exist.</p>\n";
      exit;
  }
Note the "bolded" line. It may help to add the connector to the
mysql_select_db command. By default, mysql_select_db should take
the latest link, but it never hurts to add some extra information.

If this does not work, try

Mysql
Code:
#general db test
> mysql -u root -p #as suggested
> use mysql;
> select * from user;
also try there
Code:
#specific db test
> show databases; #does gallery exist at all?
> use gallery;
> show tables;
If this command works, then it's a PHP issue for almost certain.
And since the mysql_connect seems to work ...
Otherwise, check, as also suggest, whether root really has permission
to gallery - which would be strange if not using a default installation.

Cheers!