Get table prefix

Is there a way to get the table prefix after connecting to the database?

I use wordpress and I need to get the table prefix, but outside of the whole wordpress installation. My script is currently connecting to the database, but I need a table prefix to be included in some parts of the script.

Any idea?

Thanks in advance

+4
source share
2 answers
<?php $root = realpath($_SERVER["DOCUMENT_ROOT"]); require "$root/wp-blog-header.php"; function get_table_prefix() { global $wpdb; $table_prefix = $wpdb->prefix . "outsider_plugin"; return $table_prefix; } // echo get_table_prefix(); ?> 

Thanks Mac, your idea will help me solve the problem using a similar approach.

+4
source

create any php file, outside wordpress, <?php require('wp-blog-header.php'); echo $wpdb->base_prefix; ?> <?php require('wp-blog-header.php'); echo $wpdb->base_prefix; ?>

Please use the correct path for wp-blog-header.php in require

+3
source

Source: https://habr.com/ru/post/1416512/


All Articles