How to test PHP 7 and WordPress MySQL/MariaDB Database connectivity using a PHP script

To test PHP 7 and WordPress MySQL/MariaDB database connectivity using a PHP script, you can use the following steps:

  1. Create a new PHP file with a .php extension, for example test.php

  2. Open the file using a text editor and add the following code:

 
<?php
$host = "hostname";
$user = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = mysqli_connect($host, $user, $password, $dbname);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
mysqli_close($conn);
?>

  1. Replace hostname, username, password, and database_name with the appropriate values for your setup.

  2. Save the file and place it on your web server.

  3. In your web browser, navigate to the URL where the file is located.

  4. If the connection is successful, you will see the message “Connected successfully”. If the connection fails, you will see an error message indicating the reason for the failure.

This script tests the PHP MySQLi extension’s ability to connect to the specified database using the specified username and password. If successful, this means that PHP 7 and WordPress can communicate with the MySQL/MariaDB database.

Leave a Comment