I am creating a WordPress plugin and in my plugin i need to do some SQL statements ,in the site i am working on i have access to WP-admin but i cant get to the files to get database name and password from WP-config that i need in

 mysqli_connect("host", "user_name", "password","database_name");

i believe there is a way to do that in PHP like all plugins in WordPress but i couldn't find out how !

  • 2
    Why you need a separate mysql connection? You can use wpdb to easily handle the job. It's secure and standard way to do things within plugin. read more here developer.wordpress.org/reference/classes/wpdb Feb 8, 2021 at 8:48
  • thanks this is the clue i needed @Sabbir Hasan
    – anna
    Feb 8, 2021 at 9:36
  • You are welcome. Glad to know I could help you. Feb 8, 2021 at 9:58
  • Also, Anna, while Sabbir Hasan is 100% correct and you should look to use $wpdb, you can always check your wp-config.php file for the full database credentials. Feb 8, 2021 at 14:00
  • thanks your answer is great too!! actually i found it easier since i already used SQL statements in my code @ Tony Djukic
    – anna
    Feb 9, 2021 at 17:09

1 Answer 1


both answers were great and helped me a lot ,i used the following to get to wp-config file without really Knowing all database details

      include_once ('../wp-load.php');
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD , DB_NAME);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.