qadenza :
trying to get an array of databases in localhost using PDO
$user = 'root';
$server = 'localhost';
$db = new PDO("mysql:host=$server", $user);
$sql = "show databases";
$st = $db->prepare($sql);
$st->execute();
$arr = $st->fetchAll(PDO::FETCH_ASSOC);
foreach($arr as $el){
echo $el . '<br>'; // error - array to string conversion
}
also tried:
$arr = $st->fetch(PDO::FETCH_ASSOC);
result - only the first database is echoed
Any help?
Bernd Buffen :
Get the Information from the information schema like:
SELECT `SCHEMA_NAME` FROM `information_schema`.`SCHEMATA`;
There are also more infos about the databases (schemas)
sample
MariaDB [(none)]> SELECT `SCHEMA_NAME` FROM `information_schema`.`SCHEMATA`;
+--------------------+
| SCHEMA_NAME |
+--------------------+
| bernd |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>