Gets the name of the database this Connection is connected to.
public getDatabase ( ) : string | ||
return | string |
use Doctrine\DBAL\DriverManager; $conn = DriverManager::getConnection([ 'dbname' => 'my_database', 'user' => 'my_user', 'password' => 'my_password', 'host' => 'localhost', 'driver' => 'pdo_mysql', ]); $databaseName = $conn->getDatabase(); echo "Connected to database: " . $databaseName;This code creates a connection to the MySQL database named 'my_database', using the username 'my_user' and password 'my_password' on the local host. It then calls the getDatabase() method on the connection object and displays the name of the database. The package library used in this example is the Doctrine DBAL (Database Abstraction Layer), which provides a simple database abstraction layer and SQL abstraction for PHP.
public getDatabase ( ) : string | ||
return | string |