Jump to content

Recommended Posts

Posted

There's more than one way to do this.

 

1) mysql_field_flags() function in PHP

 

If the field is indexed, the string returned by mysql_field_flags() will contain "primary_key", "unique_key", or "multiple_key". I'd suggest searching the returned string for "_key" (common to all 3).

 

2) 'SHOW INDEX FROM table_name' query

 

You could run a SHOW INDEX query on the table containing your field (which returns a table), and search for a record containing your field (by examining the 'Column_name' field of each record). If the field is indexed, it will be present, and if it is not, it won't.

 

3) 'DESCRIBE table_name field_name' query

You could run a DESCRIBE query on the table and field, which will return a single record containing information about your field. If the field is indexed, the "Key" column will contain "PRI", "UNI", or "MUL". Otherwise, the "Key" column will be empty.

 

To get a better idea of what SHOW INDEX and DESCRIBE queries return, you can run them in the SQL tab in phpMyAdmin and view the results in your browser.

 

Hope this helps...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...