gigtech 0 Newbie Poster

Hi,
I have been trying to see how it is possible to get the name of the primary key column from the database by checking the constraint name. I have, up until now been unsuccessful. I have tried the below and I get nothing returned and no errors as well. Also, I am trying to find out how the code would differ for the foreign key.

By the way this is to be used in PHP so it should be able to return the results with no problem in PHP 4/5

Thanks

$query="SELECT COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name='".$tablename."' AND CONSTRAINT_NAME='PRIMARY'";