Page 1 of 1
How to read all tables and fields in a database
Posted: Sun Aug 07, 2005 8:36 am
by raghavan20
I want find all tables in a database.
I want to extract all fields from each table.
I want to extract all values in each field
How to use PHP to do the above?
Posted: Sun Aug 07, 2005 8:41 am
by timvw
If you are using MySQL the following queries should get you started (it's only a matter of iterating through all the queries that can return multiple rows)
Code: Select all
SHOW DATABASES;
USE database;
SHOW TABLES;
SHOW COLUMNS FROM table;
SELECT DISTINCT column FROM table;
Posted: Sun Aug 07, 2005 8:41 am
by feyd
check into mysqldump or other various utilities in its goodie-bag..
SELECT ... INTO OUTFILE works nicely too.
Posted: Sun Aug 07, 2005 9:13 am
by raghavan20
I am actually thinking of building a system to create backup the database.
Do you think the commands you specified are the common ones used for a backup operation?
Do I have to run all those commands using mysql_query and use mysql_fetch_array, mysql_num_rows to extract results?
Do I have to write them into a file?
Is there is a standard way how it should be written into a file to read from it later on ?
Posted: Sun Aug 07, 2005 9:15 am
by feyd
look at mysqldump's output. It's very standard. (potentially check out phpMyAdmin's as well) very similar to mysqldump, but their own cooking..