You need to correctly configure the remote access. Here is an example of full code you will need to establish remote mysql connection.
<?php
function getdb(){
$servername = "46.101.5.233"; // put your cloudways server IP here
$username = "qxxfumxxxbd";
$password = "xxxxbQxxmM";
$db =...