Get DB name in mysql connection

2

Well I make a connection to mysql DB like this:

// Conecta-se ao banco do servidor
ini_set('default_charset', 'UTF-8');
$mysqli = mysqli_connect('127.0.0.1', 'root', '123', 'teste');
Query($mysqli, "SET NAMES utf8");

How can I retrieve the name of the BD teste through the $mysqli variable that contains the connection.

    
asked by anonymous 10.08.2017 / 15:07

1 answer

4

Use the MySQL database () function to return the name of the connection database.

SELECT database()

In php with MySQLi it looks like this:

$db = new mysqli('localhost', 'usuario', 'senha', 'db003-producao');
$result = $db->query('select database() as db');
$registro = $result->fetch_array();
echo $registro[0];
    
10.08.2017 / 15:15