MySQLi - Connect Error



Syntax

int mysqli_connect_errno ( void )

Definition and Usage

It returns a string description of the last connect error.

Example

Try out following example −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die("Connection failed: " . mysqli_connect_error());
   } 
   echo "Database connected";
   mysqli_autocommit($conn,FALSE);
   mysqli_query($conn,"INSERT INTO tutorials_auto (id,name)
   
   VALUES (10,'sai')");
   mysqli_commit($conn);
   
   mysqli_close($conn);
?>

The sample output of the above code should be like this −

Database connected

In the above example, if you give wrong authentication details, than it gives last connect error.

mysqli_useful_functions.htm
Advertisements