show mysqli_query error
snippet in sql

show mysqli_query error

user8964


<?php

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

  
if (mysqli_connect_errno()) {

  echo "Failed to connect to MySQL: " . mysqli_connect_error();

  exit();
}

// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName)
VALUES ('Glenn')")) {
  echo("Error description: " . mysqli_error($con));
}

 
mysqli_close($con);

?>
 

mysqli error

user2730


<?php

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

  
if ($mysqli -> connect_errno) {

  echo "Failed to connect to MySQL: " . 
  $mysqli -> connect_error;
  
  exit();

  }

// Perform a query, check for error
if (!$mysqli -> query("INSERT INTO Persons (FirstName)
VALUES ('Glenn')")) {
  echo("Error description: " . $mysqli -> error);

  }

 
$mysqli -> close();
?>