swa66 - 9:31 pm on Feb 20, 2013 (gmt 0)
127.0.0.1 vs localhost
localhost and 127.0.0.1 are NOT the same when it comes to PHP talking to mysql.
When given "localhost" it will use a unix domain socket
When given "127.0.0.1" it will use a TCP connection.
You can compile mysql to not use the unix domain socket and/or when doing a chroot thing it might be a lot harder to get the unix domain socket to work.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
is interesting. In essence it's PHP telling you that where you pointed it (localhost), from the configuration it has, there is no mysql listening.
Do you have control over the mysql database being running or not ?
-> I'd take it up with those running the server - they should be able to tell you where it is listening.
mysql vs mysqli
You have a number of methods for PHP to connect to a mysql database. The most common you see in tutorials is obsolete (mysql). It is replaced with mysqli (note the i). The main difference is that is is not obsolete and that it does support things like prepared statements (which are IMHO essential to good and secure programming).
Anything new or anybody learning really should not use the obsolete mysql way of doing things, and focus on e.g. mysqli instead.
mysql: [php.net...] [OBSOLETE]
mysqli: [php.net...] [CURRENT]
The third option is "PDO": [php.net...]