0

How would I fetch the name of all the fields in a table of a database using PHP Data Objects?

1 Answer 1

3

to do this you have to query the db schema. In MySQL, there is a system generated database called information_schema.

from within it, you could run:

SELECT column_name
FROM COLUMNS
WHERE table_name = 'desired_table'
AND table_schema = 'database_name'
Sign up to request clarification or add additional context in comments.

2 Comments

I also have a lot of databases with tables that have a certain tablename e.g. browers.. and it returns all of that data..
SELECT column_name FROM COLUMNS WHERE table_name = 'desired_table' AND table_schema = 'database_name'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.