As some users have suggested (and is the best way), return the mysqli instance
function getConnected($host,$user,$pass,$db) {
$mysqli = new mysqli($host, $user, $pass, $db);
if($mysqli->connect_error)
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
return $mysqli;
}
Example:
$mysqli = getConnected('localhost','user','password','database');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…