Test connection to MySQL Database using PHP

Create a blank new file called “testmysql.php” (without the quotes) and paste the following code snippet:


$myLink = mysqli_connect( 'localhost', 'my_user', 'my_password', 'my_database' ); 

if ( !$myLink ) { 

    die( 'Could not connect to MySQL: ' . print_r( mysqli_error_list( $myLink ) ) ); 


echo 'Connection OK'; 



NOTE: Replace placeholders “my_user”, “my_password” and “my_database” for your current values.

Now you need to navigate to the corresponding page:


You should see a “Connection OK” message and if there’s an error, it’ll display the error number and description.