Hello guys this is my first time asking a question on this site. I usually find all the answer somewhere or the other but not this time so I kindly request all your help to solve my minor problem here’s the problem:
Problem:
I use XAMPP and I’m unable to print error/else message in my php code when I connect to myPHPadmin. If the connection is established then no problem but when I intentionally put wrong password in $password="WRONG PASSWORD"
just to check if I’m getting the error message but unfortunately instead of getting my custom error message i get system generated error like: “Fatal error: Uncaught mysqli_sql_exception: Access denied for user ‘root’@’localhost’ (using password: YES) in C:xampphtdocsamanconnect.php:8 Stack trace: #0 C:xampphtdocsamanconnect.php(8): mysqli_connect(‘localhost’, ‘root’, Object(SensitiveParameterValue)) #1 {main} thrown in C:xampphtdocsamanconnect.php on line 8”
here’s the code:
<?php
echo "Welcome to MySQL-PHP connection<br>";
$servername = "localhost";
$username = "root";
$password = "WRONG PASSWORD";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Failed to establish connection: " . mysqli_connect_error());
}
echo "Connection is successful<br>";
?>
also in the following code when the i want to execute else statement by executing a code in which database of same name already exists:
<?php
echo "Welcome to MySQL-PHP connection<br>";
$servername = "localhost";
$username = "root";
$password = ""; // Remove the space between the quotes
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Failed to establish connection: " . mysqli_connect_error());
}
echo "Connection is successful<br>";
$sql= "CREATE DATABASE AmanDB";
$result= mysqli_query($conn, $sql);
if($result){
echo "The Database has been successfully created<br>";
}else{
echo "Creating Database was unsuccessful due to: ". mysqli_error($conn);
}
?>
please help
I tried the following using ChatGPT:
- adding error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
- my error reporting
display_errors=on
is on in “Php.ini” - restarting my xampp