I am having a problem in getting the string name of the currently selected database.
this is what i did.. i am trying to echo the name of the database but it produces an error "Warning: mysql\_fetch\_array() expects parameter 1 to be resource"

```
<?php
$dbcon = mysql_connect("localhost", "root", "")
        or die(mysql_error()."Not Connected");

$sql = mysql_query("select database()");
$row = mysql_fetch_array($sql);
echo "db ".$row[0];

```

?>

i need to get the selected database name because i will use it for

```
mysql_select_db()

```
['https://Stackoverflow.com/questions/15719092', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1647596/']
You should either select a database right after connecting using your login credentials. Or, if you want to see what databases the `root` user has access to, use:

```
SHOW DATABASES;

```
first, I would suggest you use mysqli functions instead of mysql as they are being deprecated. 

Then, you just select the database by adding the database name in the parameter to mysql\_select\_db():

```
  mysql_select_db('dbname');

```

note that another advantage of mysqli is you can specify the database in the connect string