I wrote this function which can do it in PHP
<?
define("DB_HOST", "localhost");
define("DB_NAME", "*****");
define("DB_USER", "*****");
define("DB_PASS", "*****");
// this script requires php 5.3 or later
$mydb = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($mydb->connect_error) {
die("Connect Error (" . $mydb->connect_errno . ") " . $mydb->connect_error);
}
/**
* Returns an associative array containing information
* about a field in a particular table in a particular
* db. The string parameters are case-sensitive I think.
*
* @param mysqli $db A mysqli db object representing your database connection
* @param string $table The name of the table containing the field of interest
* @param string $field The name of the field you want information about
*
*/
function get_field_info($db, $table, $field) {
try {
if ($query_result = $db->query(" EXPLAIN `$table`")) {
while($row = $query_result->fetch_assoc()) {
if ($row["Field"] == $field) {
$result = $row;
$query_result->free();
return $result;
}
}
} else {
throw new Exception("There was a problem running the query:" . $db->error());
}
} catch (Exception $e) {
}
}
$info = get_field_info($mydb, "business", "id");
print_r($info);
?>
It returns the following for me:
Array
(
[Field] => id
[Type] => int(6) unsigned
[Null] => NO
[Key] => PRI
[Default] =>
[Extra] => auto_increment
)