Get the last error code for the most recent function call, if any in PHP

Description

The following code shows how to get the last error code for the most recent function call, if any.

Example


/*w  w  w  .  j a va 2  s.co m*/
<?php
     $con=mysqli_connect("localhost","root","","test");
     // Check connection
     if (mysqli_connect_errno()){
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }

     // Perform a query, check for error
     if (!mysqli_query($con,"INSERT INTO employee(Name) VALUES ('XML')")){
        echo("Errorcode: " . mysqli_errno($con));
     }

     mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented