reenadak

List all MySql Database

Sep 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // FILENAME: LIST_MYSQL_DBS.PHP
  2.  
  3. define( 'NL', "\n" );
  4. define( 'TB', ' ' );
  5.  
  6. // connecting to MySQL.
  7. $conn = @mysql_connect( 'xyz.com or localhost', 'username', 'password' )
  8. or die( mysql_errno().': '.mysql_error().NL );
  9.  
  10. // attempt to get a list of MySQL databases
  11. // already set up in my account. This is done
  12. // using the PHP function: mysql_list_dbs()
  13. $result = mysql_list_dbs( $conn );
  14.  
  15. // Output the list
  16. echo '<ul>'.NL;
  17.  
  18. ///* USING: mysql_fetch_object()
  19. // ---------------------------
  20. while( $row = mysql_fetch_object( $result ) ):
  21. echo TB.'<li>'.$row->Database.'</li>'.NL;
  22. endwhile;
  23. //*/
  24.  
  25. /* USING: mysql_fetch_row()
  26. // ------------------------
  27. while( $row = mysql_fetch_row( $result ) ):
  28. echo TB.'<li>'.$row[0].'</li>'.NL;
  29. endwhile;
  30. //*/
  31.  
  32. /* USING: mysql_fetch_assoc()
  33. // --------------------------
  34. while( $row = mysql_fetch_assoc( $result ) ):
  35. echo TB.'<li>'.$row['Database'].'</li>'.NL;
  36. endwhile;
  37. //
  38. */
  39.  
  40. echo '</ul>'.NL;
  41.  
  42. // Free resources / close MySQL Connection
  43. mysql_free_result( $result );
  44. mysql_close( $conn );
Add Comment
Please, Sign In to add comment