Here is mysqli_connect() as defined in the PHP manual:
mysqli_connect([ string $host = ini_get("mysqli.default_host")
[, string $username = ini_get("mysqli.default_user")
[, string $passwd = ini_get("mysqli.default_pw")
[, string $dbname = ""
[, int $port = ini_get("mysqli.default_port")
[, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
Should I just do this for all the arguments?:
class MyClass {
private $conn;
public function __construct($host = '') {
if($host == '') {
$host = ini_get('mysqli.default_host');
}
$this->conn = mysqli_connect($host);
}
}
If I do that for all the method arguments will it correctly wrap mysqli_connect()? Is there a more elegant may to do it?
EDIT:
After seeing Francios’s answer and thinking about it a little more this seems like the best way to do it:
class MyClass {
private $conn;
public function __construct($host = '',
$username = '',
$passwd = '',
$dbname = '',
$port = 0,
$socket = '') {
$this->conn = call_user_func_array('mysqli_connect', func_get_args());
}
}
Would that wrap it correctly? The only thing that worries me is the $port because it is not a string.
You could use
call_user_func_arrayassuming that your class expects the parameters to be the exact same asmysqli_connect.With that said, the more elegant way is simply to extend the MySQLi class: