get table prefix

is there any way to obtain the table prefix after connect to the database ?

I’m using wordpress and I need to obtain the table prefix but outside the whole wordpress installation. Currently my script connect to the database, but I need the table prefix to incorporate in some parts of the script.

Read More

Any idea ?

Thanks in advance

Related posts

Leave a Reply

2 comments

  1. <?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 mack, your idea help me to solve the problem, using a similar approach.

  2. Create any PHP file, outside WordPress,

    <?php
        require('wp-blog-header.php');
        echo $wpdb->base_prefix;
    ?>
    

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