recover BD name of a mysql and php connection

Asked

Viewed 79 times

0

Good make the connection in my mysql so:

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

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

It is possible to do this?

2 answers

2

Run an 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> 
  • OK, but I want to return the BD name of the connection that is in the variable '$mysqli'. I tried like this: '$mysqli->query("select database()");' but it did not work

-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]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.