Have a look at your my.cnf as this defines the location of the socket file that it is attempting to pick up. It is currently defined with /var/mysql/mysql.sock but according to the attempt that did work this should have been /Applications/MAMP/tmp/mysql/mysql.sock.
The location of the my.cnf is determined in the following order:
Today is my first day fooling around with MySQL/php so I'm not entirely able to solve the problem based off of what you wrote, but it definitely gave me enough info to do some research on my own. That in itself is a huge help. Thanks again!
No problem, there are two ways in which you can connect to a database, the first way is using a host or ip address and a port (default is 3306), the second way is using sockets (on a UNIX/Linux/Mac OS) and on Windows shared memory. The sockets and shared memory can only be accessed from the local machine. If you were to perform a remote connection then it will use the IP and port method.
The file my.cnf is used to configure the default way the client connects to the database. In your case it is saying that it will connect with a socket. A socket on UNIX/LInux/Mac OS is a special file on the operating system. The MySQL server creates this file when it is launched and listens for any connections coming in on this file. The location of the socket file is key to access the database server. If the client attempts to connect to a file that does not exist then no connection can be established. So you need to make sure that the client connects correctly.
You have overwritten the default in the second PHP piece of code with the correct location to the socket file. This means that your client socket configuration in my.cnf does not appear to be correct.