'WP Function to retrieve database connection
Is there a function or command that pulls the db connection info from the WP blog? I am writing a Plugin which would have to connect to the db to retrieve the info, wondering if there was one single command/function i could call which could connect. this would make the plugin portable and would work on any WP blog. is this possible?
Solution 1:[1]
See the Interfacing with the Database docs.
You should just be able to use the global (curse you, Wordpress) variable $wpdb in your plugin functions, ie:
global $wpdb;
//do stuff
Plugins also have a few methods for storing "options" in the database. I just found this article, it details things fairly well.
Solution 2:[2]
If you want to create your own query with database then you can try this
require_once('wp-config.php');
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
You will get table prefix on $table_prefix this variable. I think it will help you. For preview you can check my github repo https://github.com/webdeveloperkanai/flutter-wordpress-blog-view-app-full-setup
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zombat |
| Solution 2 | Web Developer Kanai |
