CodeIgniter Forums
Get db name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Get db name (/thread-78986.html)



Get db name - pippuccio76 - 04-05-2021

hi sorry for english , there is a way to get db name ? 

i have this code to get db table :

Code:
           $db = \Config\Database::connect();

        $tableList = array();


        $query = $db->query("SHOW TABLES");
        $results = $query->getResult();

        foreach ($results as $row)
        {
           $tableList[] =$row->Tables_in_name_of_db;
        }

          $data['tableList']= $tableList;


Can i get the name to use in this method ? i know that db name are in .env but i want create a tool and i must get it


RE: Get db name - InsiteFX - 04-05-2021

If you just need the current database name, you can use MySQL's SELECT DATABASE() command.
This is not tested but give it a try.

PHP Code:
$dbname $db->query("SELECT DATABASE()"); 



RE: Get db name - nfaiz - 04-05-2021

(04-05-2021, 07:12 AM)pippuccio76 Wrote: hi sorry for english , there is a way to get db name ? 

i have this code to get db table :

Code:
       $db = \Config\Database::connect();

$tableList = array();


$query = $db->query("SHOW TABLES");
$results = $query->getResult();

foreach ($results as $row)
{
   $tableList[] =$row->Tables_in_name_of_db;
}

      $data['tableList']= $tableList;


Can i get the name to use in this method ? i know that db name are in .env but i want create a tool and i must get it

PHP Code:
$dbname $db->database