Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 855
user983248 Avatar asked Jun 07 '12 06:06

user983248


People also ask

How do I find the table prefix in database?

When you are connected to the database - look at the name of every table of the website. It will begin with a group of letters and the underscore symbol ('_'). These letters and the underscore is the database prefix for your website. An example prefix looks like this: 'jos_'.

What is a table prefix?

A table prefix is a prefix that is added to every tablename, as the name implies. – Mathias Lykkegaard Lorenzen.

How do I find the table prefix in MySQL?

To list all tables with some prefix, "any number of symbols" wildcard ( % ), should be used. _ is also a wildcard, representing any single symbol, and therefore it should be escaped.


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

like image 53
user983248 Avatar answered Oct 23 '22 13:10

user983248