I installed apache2, php5, mysql-server, php5-mysql, phpmyadmin in that order on Ubuntu 12.04 with the Software Center. Apache and PHP works fine, no problems. Also, if I try to work with MySQL via phpmyadmin, everything works as expected. Problems start, when I want to use MySQL via PHP. For this I tried the following script:
$connection = mysql_connect($host, $user, $pw) OR die(mysql_errno()." ".mysql_error()); mysql_select_db($db, $connection) OR die(mysql_errno()." ".mysql_error());
This returns "1046 No database selected". I'm sure that the database exists, I even tried it with the standard "test"-database and root as the user. What made me really curious, is that when I use a non-existent user ("asdf"), the same message appears and no failure from the mysql_connect-function.
This leads me to the suspicion, that I struggle with user rights in the Linux system, because it works with phpmyadmin, which is not installed via a webinstaller but via the Software Center. I can only guess that hence, phpmyadmin has other rights to access MySQl than PHP, but I don't know, how to approach the problem. After trying and googleing for hours, I feel a bit lost now. Please help me.