Current Location: Home> Function Categories> mysqli::connect

mysqli::connect

Open a new MySQL server connection.
Name:mysqli::connect
Category:Uncategorized
Programming Language:php
One-line Description:Open a new MySQL server connection.

Definition and usage

The connect() / mysqli_connect() function is used to open a new MySQL server connection.

Example

Example 1 - Object-Oriented Style

Open a new MySQL server connection:

 <?php
$mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ;

// Check the connection
if ( $mysqli -> connect_errno ) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error ;
  exit ( ) ;
}
?>

Example 2 - Procedural Style

Open a new MySQL server connection:

 <?php
$con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ;

// Check the connection
if ( mysqli_connect_errno ( ) ) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ;
  exit ( ) ;
}
?>
Similar Functions
Popular Articles