How can one view the connection properties and parameters when establishing a database connection in PHP to troubleshoot issues with a PHP building tool?
To troubleshoot issues with a PHP building tool related to establishing a database connection, you can view the connection properties and parameters being used. This can help identify any errors or misconfigurations that may be causing the problem. By examining the connection details, you can ensure that the correct database credentials, host, port, and database name are being used.
// View connection properties and parameters
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";
echo "Server: " . $servername . "<br>";
echo "Username: " . $username . "<br>";
echo "Password: " . $password . "<br>";
echo "Database Name: " . $dbname . "<br>";
// Establish a database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";