How to get a list of databases?

前端 未结 4 645
醉梦人生
醉梦人生 2020-12-17 00:34

I was wondering if there\'s a way in PHP to list all available databases by usage of mysqli. The following works smooth in

4条回答
  •  暖寄归人
    2020-12-17 01:15

    I realize this is an old thread but, searching the 'net still doesn't seem to help. Here's my solution;

    $sql="SHOW DATABASES";
    $link = mysqli_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql: ' . mysqli_error($link).'\r\n');
    
    if (!($result=mysqli_query($link,$sql))) {
            printf("Error: %s\n", mysqli_error($link));
        }
    
    while( $row = mysqli_fetch_row( $result ) ){
            if (($row[0]!="information_schema") && ($row[0]!="mysql")) {
                echo $row[0]."\r\n";
            }
        }
    

提交回复
热议问题