最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to get database connection details without longing to cpanel in WordPress?

programmeradmin0浏览0评论

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
  • 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/reference/classes/wpdb – Sabbir Hasan Commented Feb 8, 2021 at 8:48
  • thanks this is the clue i needed @Sabbir Hasan – anna Commented Feb 8, 2021 at 9:36
  • You are welcome. Glad to know I could help you. – Sabbir Hasan Commented 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. – Tony Djukic Commented 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 Commented Feb 9, 2021 at 17:09
Add a comment  | 

1 Answer 1

Reset to default 0

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

      require_once('../wp-config.php');
      include_once ('../wp-load.php');
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD , DB_NAME);
发布评论

评论列表(0)

  1. 暂无评论