I want to show all table names in my plugin development. I know how to do that in core PHP.
I am trying like this:
$mytables=$wpdb->get_results("SHOW TABLES");
foreach ($mytables as $mytable)
{
echo $mytable;
}
As I said in my comment, you should use nested foreach loops.
global $wpdb;
$mytables=$wpdb->get_results("SHOW TABLES");
foreach ($mytables as $mytable)
{
foreach ($mytable as $t)
{
echo $t . "<br>";
}
}
Then you don't need to know the name of your database, because SHOW TABLES
will create the column name "Tables_in_" (without < and > of course).
check the following function to get list of tables
$mytables=$wpdb->get_results("SHOW TABLES FROM ".$wpdb->dbname);
foreach ($mytables as $mytable)
{
echo($mytable->Tables_in_wordpress).'<br/>';
}
die;
There is a native function in WordPress for that: wpdb::tables( string $scope = 'all', bool $prefix = true, int $blog_id ). See https://developer.wordpress.org/reference/classes/wpdb/tables/ for details ;-)