If you're willing to use a lot of functions to get a little information about fields in a table, this function is for you. If you just want to get all the information you can find, you can use this:
<?php
function getPrimaryKeyOf($table) {
$keys = Array();
$query = sprintf("SHOW KEYS FROM `%s`", $table);
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
if ( $row['Key_name'] == 'PRIMARY' )
$keys[$row['Seq_in_index'] - 1] = $row['Column_name'];
}
return $keys;
}
function getTableInformationOf($table) {
$information = array(
"auto" => "",
"primary" => array(),
"fields" => array()
);
$information['primary'] = $this->getPrimaryKeyOf($table);
$result = mysql_query("DESC `$table`");
while ( $field = mysql_fetch_assoc($result) ) {
$information['fields'][] = $field;
if ( $field['Extra'] == "auto_increment" )
$information['auto'] = $field['Field'];
}
return $information;
}
?>