Home > AI > Language > PHP > mysqli >

mysqli_connect

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") 
)

Example

$db_host = '';
$db_dbname = '';
$db_user = '';
$db_password = '';

/* You should enable error reporting for mysqli before attempting to make a connection */
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = mysqli_connect($db_host, $db_user, $db_password, $db_dbname);
// Check connection
if($con === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
} else {
    printf("Success... %s\n", mysqli_get_host_info($con));
}

Leave a Reply