HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP MySQLi Reference : Open a new connection to the MySQL server, with extra connect options
The real_connect() / mysqli_real_connect() function opens a new connection to the MySQL server.
This function differs from connect() in the following ways:
Object oriented style:
Procedural style:
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
host | Optional. Specifies a host name or an IP address |
username | Optional. Specifies the MySQL username |
password | Optional. Specifies the MySQL password |
dbname | Optional. Specifies the default database to be used |
port | Optional. Specifies the port number to attempt to connect to the MySQL server |
socket | Optional. Specifies the socket or named pipe to be used |
flag | Optional. Specifies different connection options. Possible values:
|
Return Value: | TRUE on success. FALSE on failure |
---|---|
PHP Version: | 5+ |
PHP Changelog: | PHP 5.6: Added MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT flag |
Open a new connection to the MySQL server, with extra connect options:
<?php
$con = mysqli_init();
if (!$con) {
die("mysqli_init failed");
}
// Specify connection timeout
mysqli_options($con,
MYSQLI_OPT_CONNECT_TIMEOUT, 10);
// Specify read options from named file instead of my.cnf
mysqli_options($con, MYSQLI_READ_DEFAULT_FILE, "myfile.cnf");
mysqli_real_connect($con,"localhost","my_user","my_password","my_db");
?>
❮ PHP MySQLi Reference