Need to find external database prefix

I am creating a plugin for WordPress, and part of the plugin requires me to connect to an external WordPress site and use this external database to get some information. I made a connection and I accessed an external database $wpdbusing the following code:

global $new_wpdb;

define( 'BLOCK_LOAD', true ); 
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' ); 
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php' ); 
$new_wpdb = new wpdb( $username, $password, $dbname, $servername); 
$new_wpdb->show_errors();

When I use print_r($new_wpdb);, I get an array, and I can see the values ​​for username, password, etc., but there is no value for prefixor base_prefix. It simply displays the following for the prefix:

[prefix] => [base_prefix] =>

How to get the prefix used by an external database?

+4
source share
1 answer

WordPress?

require_once wp-config.php , $table_prefix.

, WordPress ( ), SHOW TABLES LIKE '%wp_users', $table_prefix = str_replace('wp_users', '', $result);

+1

All Articles