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
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_'.
A table prefix is a prefix that is added to every tablename, as the name implies. – Mathias Lykkegaard Lorenzen.
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.
<?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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With