note 35043 modified in function.mysql-field-flags by didou
| From: | didou@php.net | Date: | Sun, 17 Aug 2003 15:48:25 +0000 |
| Subject: | note 35043 modified in function.mysql-field-flags by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54540@lists.php.net to get a copy of this message | ||
returns primary keys of a table using 'show keys'
although it is possible to use desc, show keys offers possible enhancements such a getting sequence
in index along with it
function getPrimaryKeyOf($table, $link) {
$pk = Array();
$sql = 'SHOW KEYS FROM
'.$table.'';
$res = mysql_query($table, $link) or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
if ($row['Key_name']=='PRIMARY')
array_push($pk, $row['Column_name']);
}
return $pk;
}
--was--
returns primary keys of a table using 'show keys'
although it is possible to use desc, show keys offers possible enhancements such a getting sequence
in index along with it
function getPrimaryKeyOf($table, $link) {
$pk = Array();
$sql = 'SHOW KEYS FROM '.$table.'';
$res = mysql_query($table, $link) or die(mysql_error());
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
if ($row[Key_name]=='PRIMARY')
array_push($pk, $row[Column_name]);
}
return $pk;
}
http://www.php.net/manual/en/function.mysql-field-flags.php