I wrote a simple php code to connect to the mysql server as below
The error is here:
$hostname = "localhost:81";
You are not connecting to MySQL, but to Apache server. If you didn't change MySQL port just use
$hostname = "localhost";
you forget to specify the database name after entering database name try again. The syntax should be like this
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>