Search code examples
phpmysqldatabasewordpress

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.

Any idea ?

Thanks in advance


Solution

  • <?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.