How To Make Connection To WordPress Data Base In A Plugin?

I found the answer my self. First open your wp-config.php and check the bottom of file that Is that contain the below code?…

if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . "https://wordpress.stackexchange.com/");

If yes then add the below code to make the connection in your plugin PHP files to connect with wp-config.php file that contain Database Name, Database UserName, Database Password, Database Host… …

require_once(ABSPATH . 'wp-config.php');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($connection, DB_NAME);

And you will get connection to WordPress database…

Leave a Comment