May 2, 2002 #1 ulag Programmer Joined Sep 4, 2001 Messages 23 Location US I use mysql. I want to know what fields are primary or unique keys? I need to find by PHP. Please help me. Thanks. ulag
I use mysql. I want to know what fields are primary or unique keys? I need to find by PHP. Please help me. Thanks. ulag
May 2, 2002 #2 mtlintz Technical User Joined May 2, 2002 Messages 1 Location US This link http://www.php.net/manual/en/function.mysql-field-type.phpshows how to do something like that Upvote 0 Downvote
This link http://www.php.net/manual/en/function.mysql-field-type.phpshows how to do something like that
May 3, 2002 #3 DumTech Technical User Joined Mar 23, 2001 Messages 153 Location US There's probably a simpler way to do it, but this function works ok for me. Code: function get_primkey($table) { $result = mysql_list_fields($dbname,$table); if (!$result) { return false; } while ($field = mysql_fetch_field($result)) { if ($field->primary_key) { $pri_key = $field->name; return $pri_key; } } } Matt matt@paperlove.org If I can help, I will. Upvote 0 Downvote
There's probably a simpler way to do it, but this function works ok for me. Code: function get_primkey($table) { $result = mysql_list_fields($dbname,$table); if (!$result) { return false; } while ($field = mysql_fetch_field($result)) { if ($field->primary_key) { $pri_key = $field->name; return $pri_key; } } } Matt matt@paperlove.org If I can help, I will.