Last active
May 2, 2019 08:58
-
-
Save asharirfan/c41b7487bc11fb8c2ec097ae1b2e8051 to your computer and use it in GitHub Desktop.
๐พ DB Connectivity Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* DB Connectivity Tests | |
* | |
* @package dbtest | |
*/ | |
// Define database constants. | |
define( 'DBTEST_HOST', 'localhost' ); // REPLACE THE CONSTANT VALUE WITH YOUR HOST. | |
define( 'DBTEST_USER', 'root' ); // REPLACE THE CONSTANT VALUE WITH YOUR USERNAME. | |
define( 'DBTEST_PASSWORD', 'root' ); // REPLACE THE CONSTANT VALUE WITH YOUR PASSWORD. | |
define( 'DBTEST_DATABASE', 'local' ); // REPLACE THE CONSTANT VALUE WITH YOUR DATABASE NAME. | |
$db_connection = mysqli_connect( DBTEST_HOST, DBTEST_USER, DBTEST_PASSWORD, DBTEST_DATABASE ); // phpcs:ignore | |
if ( ! $db_connection ) { | |
echo '<h2>Error: ' . mysqli_connect_error() . '</h2>' . PHP_EOL; // phpcs:ignore | |
echo '<h3>Error number: ' . mysqli_connect_errno() . '</h3>' . PHP_EOL; // phpcs:ignore | |
exit; | |
} else { | |
echo '<h3>1. Successfully connected to MySQL database server.</h3>' . PHP_EOL; | |
$select_db = mysqli_select_db( $db_connection, DBTEST_DATABASE ); // phpcs:ignore | |
if ( ! $select_db ) { | |
echo '<h3>Unknown database "' . DBTEST_DATABASE . '"</h3>' . PHP_EOL; // phpcs:ignore | |
exit; | |
} else { | |
echo '<h3>2. WordPress MySQL database selected.</h3>' . PHP_EOL; | |
} | |
mysqli_close( $db_connection ); // phpcs:ignore | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment