I used this code to connect, This code will show error as I used password = "fd", rather I should use this password = "", I know. But I want to check whether this mysqli_connect_error() is working or not. And I found that this is not working rathe this is showing me, this error
Fatal error: Uncaught mysqli_sql_exception: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\php\database\insert_data.php:8 Stack trace: #0 C:\xampp\htdocs\php\database\insert_data.php(8): mysqli_connect('localhost', 'root', 'fd', 'mydb') #1 {main} thrown in C:\xampp\htdocs\php\database\insert_data.php on line 8
Tell me why this mysqli_connect_error() function now working?
<?php
$servername = "localhost";
$username = "root";
$password = "fd";
$dbname = "mydb";
// create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// check connection
if(!$conn){
echo "Connection failed!". mysqli_connect_error();
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('john', 'soldi', 'johnsoldi@gmail.com')";
if(mysqli_query($conn, $sql)){
echo "New records created successfully!";
}else{
echo "Error: ". $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>