I have been trying to replicate the error you are getting but am unable to reproduce it when using code sample you provided.
Also your code sample has a few mistakes, you create your connection as $sql but then check $mysqli for connection errors, you should be checking $sql. So I have changed all occurances of $mysqli to $sql and you the more conventional way to check for a connection error is to check connect_errno and then read the message from connect_error
$sql = new mysqli(null,
'your-username', // username
'your_password_or_blank_if_using_root',
'database_name',
null,
'/cloudsql/project_id:instance_name'
);
if ($sql->connect_errno) {
echo 'no';
die('Connect Error (' . $sql->connect_errno . ') '. $sql->connect_error);
} else {
echo 'yes\n';
}