MySQL Forums
Forum List  »  PHP

mysqli field flags
Posted by: Michael Hitchcock
Date: October 04, 2008 10:15PM

I am attempting to identify primary and unique keys in a database table. The code below works for the primary key but not for non-primary unique keys.
Any ideas why?



function getKey ($type) {
switch ($type) {
case 'primary':
$flag = MYSQLI_PRI_KEY_FLAG;
break;
case 'lookup':
$flag = MYSQLI_UNIQUE_KEY_FLAG;
break;
}
// $this->fields is an array of fields from the
// mysqli_result::fetch_fields method

foreach ($this->fields as $field) {
if ($field->flags & $flag) {
return $field->name;
}
}

}



Edited 2 time(s). Last edit at 10/04/2008 10:27PM by Michael Hitchcock.

Options: ReplyQuote


Subject
Written By
Posted
mysqli field flags
October 04, 2008 10:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.