If you get PHP Warning: mysql_connect(): No such file or directory and unable to connect mysql through php then change localhost to 127.0.0.1 while connecting to database
example:
$connection = mysql_connect('localhost', 'root', 'password');
to
$connection = mysql_connect('127.0.0.1', 'root', 'password');
example:
$connection = mysql_connect('localhost', 'root', 'password');
to
$connection = mysql_connect('127.0.0.1', 'root', 'password');