I'm building a custom page which queries table and field names from the current database, and performs certain actions on the tables.
I don't want to hardcode the database name into a variable.
I recall that there is a global var $DB which should be the database name, but it seems it doesn't work.
Is there a global var for the database name which can be called from a custom page?
I'm trying to get all the table names and their fields from the database into an array. Not running queries on the data.
The code works, but only if i manually add the database name like:
$row['Tables_in_MyDatabase']
// Populate the array with table names and fields
foreach ($tables_result as $row) {
$table_name = $row['Tables_in_' . $mydb]; // Assuming $mydb contains the database name
$fields_query = "SHOW COLUMNS FROM $table_name";
$fields_result = ExecuteRows($fields_query);
// Initialize an array to store fields for the current table
$table_fields = array();
// Populate the table_fields array with field names
foreach ($fields_result as $field_row) {
$field_name = $field_row['Field'];
$table_fields[] = $field_name;
}
// Add the table name and its fields to the tables_and_fields array
$tables_and_fields[$table_name] = $table_fields;
}