在 Codeigniter 4 中,如何显示数据库名称和 table 前缀?

In Codeigniter 4, how to display database name and table prefix?

到目前为止,在 codeigniter 3 中,我们可以从以下代码行中获取数据库名称和 table 前缀 (如 config/database.php 中所述)

echo $this->db->database;
echo $this->db->dbprefix('emp_table');

现在我们如何在 Codeigniter 4 中调用这些值?

我认为在 Codeigniter 4.0.1 中这就是您要找的东西


$db = \Config\Database::connect();
$Database = $db->database();
$DBPrefix = $db->getPrefix();

我希望这对你有用

CI4 中有一些变化,内部控制器的构造函数,

写入:

$db = \Config\Database::connect();
define('production',$db->database);

在你的函数中调用它:

echo(production);

切勿在 CI4 中将数据库作为函数 () 调用,避免使用此 () 并仅使用对象代替:不带 () 的数据库