CodeIgniter Forums

Full Version: Get db name
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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()"); 
(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