To test PHP 7 and WordPress MySQL/MariaDB database connectivity using a PHP script, you can use the following steps:
-
Create a new PHP file with a .php extension, for example test.php
-
Open the file using a text editor and add the following code:
$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);
-
Replace
hostname
,username
,password
, anddatabase_name
with the appropriate values for your setup. -
Save the file and place it on your web server.
-
In your web browser, navigate to the URL where the file is located.
-
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.