retrieve DB name from a mysql and php connection

0

Well I make the connection in my mysql like this:

$mysqli = mysqli_connect('127.0.0.1', 'root', '123', 'teste');

I want to know how to retrieve the name of the database through the variable that receives the connection '$ mysqli'.

Is it possible to do this?

    
asked by anonymous 03.03.2017 / 12:28

2 answers

2

Run SQL select database() to return the MySQL database name, for example:

mysql> select database();
+--------------------+
| database()         |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql> 
    
03.03.2017 / 13:01
-1

Well the solution was this one:

$mysqli = mysqli_connect($ip_bd_mysql, $login_bd_mysql, $senha_bd_mysql, "CIDADES");


$result = $mysqli->query("SELECT DATABASE()");
$row = $result->fetch_row();
printf($row[0]);
    
03.03.2017 / 14:18