I\'m learning PHP MYSQL and trying to create a database.
I\'m following this tutorial http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-f
This seems to be a common issue, as googling for it yields quite a few results. I experienced this on my two linux boxes as well (never under Windows though) and at some point I resolved to just use 127.0.0.1 on all dev servers. Basically, localhost makes the connection to the MySQL server use a socket, but your configuration doesn't point to the socket file correctly.
Here are a couple of resources that you might find useful:
http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/ - basically what @Jack suggests, but more in depth
Can't connect to MySQL on Mac -- missing mysql.sock file - here's how to locate your socket file (for some reason, my php.ini had the path wrong, and I assume your case could be similar).
I hope this helps.