Open a new connection to the MySQL server in PHP

Description

The following code shows how to open a new connection to the MySQL server.

Example


  //w w  w.j a  v  a  2 s .  co  m
<?php
    $con=mysqli_init();
    if (!$con){
       die("mysqli_init failed");
    }
   
    mysqli_options($con,MYSQLI_READ_DEFAULT_FILE,"myfile.cnf");
   
    if (!mysqli_real_connect($con,"localhost","root","","test")){
       die("Connect Error: " . mysqli_connect_error());
    }
    
    mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented