(PHP MySQL) Connect to a Database (Cont.)

mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );
This function opens a new connection to the MySQL server.

mysqli_real_connect( connection, host, username, password, dbname, port, socket, flag ) 

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. Port 3306 is the default port for the classic MySQL protocol ( port ).

if ( $conn->connect_errno )
The connect_errno function returns the error code from the last connection error, if any. Zero if no error occurred

die( 'Failed to connect to MySQL: ' . $conn->connect_error );
The connect_error function returns the error description from the last connection error, if any. NULL if no error occurred

$conn->close( );
The close function closes a previously opened database connection.

 <html><body>
 <?php
  $username = "wenchen";
  $database = "wenchen";
  $host     = "undcemmysql.mysql.database.azure.com";
  $password = "";

  // Initializing MySQLi
  $conn     = mysqli_init( );

  // Creating an SSL connection
  mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );

  // Opening a new connection to the MySQL server
  mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );

  // Connecting to the database
  if ( $conn->connect_errno )
    die( 'Failed to connect to MySQL: ' . $conn->connect_error );
  else
    echo "Successfully connect to MySQL!";

  // Closing the database connection
  $conn->close( );
 ?>
 </body></html>
                   




      Two fishes are in a tank.    
      One turns to the other and says...   
      How do you drive this thing?