1

My phpmyadmin have these databases and looks like this:

demo_db_1
information_schema
mysql
performance_schema
demo_db_2
test_db_1
test_db_2

How can I get a list of all custom databases?

Meaning: when I run a file test.php, I would like to see a list like

demo_db_1
demo_db_1
test_db_1
test_db_2

I don't want to connect to any database. Just want the list of all the created databases. How can I achieve this?

Thanks in advance

1

2 Answers 2

5

Call a mysql query with mysql_query("show databases;");

You can get list of the databases you have access to with:

SHOW DATABASES;

If you want to get the list for some other user than the user you're logged in as, you have to query the mysql.db table.

Sign up to request clarification or add additional context in comments.

1 Comment

Your welcome, Just don't forget to mark this answer as correct answer ;)
1

You can use following code :

<?php
    //mysql_connect('HostName','UserName','Password');
    mysql_connect('localhost','root','');
    $database = mysql_query("show databases;");
    while($data = mysql_fetch_assoc($database))
    {
    $fetch[] = $data;
    }
    print "<pre>";
    print_r($fetch);
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.