I am trying to connect mysql database using php. But it is running fine on local machine but not when hosted online and error appeared as mysqli_connect(): (HY000/2002): Co
In my case, AWS firewall was blocking my web server.
Adding the web servers IP address to the firewall exceptions fixed this for me.