17 February 2012

How to get all tables names that are in a certain table.

Source code viewer
  1. $tables = array();
  2. $link = mssql_connect('ip:port', 'username', 'password'); // Change database log in information.
  3. mssql_select_db('database_name', $link); // Change database name.
  4.  
  5. // Get all mssql tables and put them in variable tables.
  6. if ($link) {
  7. $result = mssql_query('select table_name from information_schema.tables order by table_name', $link);
  8. while ($row = mssql_fetch_row($result)) {
  9. $tables[] = $row[0];
  10. }
  11. else {
  12. echo 'Database connection failed while getting list of all tables in mssql.';
  13. }
  14. mssql_close($link);
  15.  
  16. // Print MSSQL table list.
  17. print_r($tables);
Programming Language: PHP