Error establishing a database connection wordpress

Error establishing a database connection wordpress

<?php
$link = mysqli_connect('hostname', 'database username', 'database password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>