When describing the structure of a table, how do you...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
willing
Forum Newbie
Posts: 2
Joined: Fri Sep 27, 2002 11:50 am
Location: UK

When describing the structure of a table, how do you...

Post by willing »

Hello. I would be very grateful if anyone could help me with a question I have.

When describing the structure of a table using PHP, how do you call for the lengths of fields. For example, names varchar (??), how do I find out the set length of this field?

I thought the answer was using the ->max_length command, but that only tells you the greatest length of any data entered in to the field!

Pleeease help me!

:roll:
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

This way would work, may not be the easiest though.

run this query "SHOW FIELDS FROM `tblCode`"
then go through the result set, do some string manipulation with the Type column and it will give you the size.
Here's what the query returns.
Field,Type,Null,Key,Default,Extra
codeID,int(14),,PRI,0,
codeName,varchar(50),YES,,NULL,
codeActive,char(1),YES,,NULL,
codeSession,varchar(4),YES,,NULL,

Might help, might not.

Keith
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

willing
Forum Newbie
Posts: 2
Joined: Fri Sep 27, 2002 11:50 am
Location: UK

Post by willing »

Thank you both for you solutions.
Post Reply