Aaron
Aaron

Reputation: 11693

PHP Data Objects Fetching A Fields Name From A Table

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

Upvotes: 0

Views: 77

Answers (1)

Julien
Julien

Reputation: 282

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'

Upvotes: 3

Related Questions