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 !
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 !
Share Improve this question edited Feb 8, 2021 at 8:12 anna asked Feb 8, 2021 at 8:07 annaanna 94 bronze badges 5 |1 Answer
Reset to default 0both answers were great and helped me a lot ,i used the following to get to wp-config file without really Knowing all database details
require_once('../wp-config.php');
include_once ('../wp-load.php');
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD , DB_NAME);
wpdb
to easily handle the job. It's secure and standard way to do things within plugin. read more here developer.wordpress/reference/classes/wpdb – Sabbir Hasan Commented Feb 8, 2021 at 8:48$wpdb
, you can always check yourwp-config.php
file for the full database credentials. – Tony Djukic Commented Feb 8, 2021 at 14:00