IMHO you cannot compare Java in general with PHP. PHP is designed for creating dynamic webpages, often using databases like MySQL (see "LAMP", Linux, Apache, MySQL, PHP) - a very effective combination.
Java is even more powerful: You can build stand-alone applications, Java-applets, and - quite fresh - JavaServerPages (JSP) which are similar to ASP.
JavaScript is no solution for working with databases, because its aim is to make webpages "slightly" dynamic but works client-sided, has neither database support nor permissions to read/write files.
By the way: PHP is very easy to implement if you're familar to C-syntax. Java needs to be studied.