Get mysql column comments with php?

I want to store information about the column in a mysql table without storing it in the field title. There is the comments thing but how can I find that using php? I don’t think this has been done before. Please help.

Thanks :wink:

I want to store information about the column in a mysql table without storing it in the field title

My apologies but I don’t understand the line of questioning. What exactly is this referring to?

You know, when you add a new column and you see the comments text box in phpmyadmin or something. How can you retrieve this using php and put it in a variable?

$db = mysql_connect("localhost","root","xxx") or die(mysql_error());
function table_description($t,$d){
    $sql = 'SHOW CREATE TABLE `' . $t . '`;';
    $query = mysql_query($sql,$d);
    $v = mysql_result($query, 0, 1);
        $p = strpos($v, "COMMENT=");
            return substr($v, $p + 8);
    return 'Table description not found';
    echo table_description('user',$db);

You can get all informations about your databases, tables, cells from information_schema database. It depends whether you have access to it or not.

@Ernie1: I said column description not the table description.

That contains no comments function at all. Any other Ideas?

Run this sql query using php (like you would any other query)

select column_comment
  from information_schema.columns
 where table_name = 'tbl_name'
   and column_name like 'the_column'

Thanks for that, wow_15 :tup:

$db = mysql_connect("localhost","root","xyz") or die(mysql_error());
mysql_select_db("database",$db) or die(mysql_error());

function table_description($t,$c,$d){
     $sql = "SELECT column_comment FROM information_schema.columns
      WHERE table_name = '$t' AND column_name LIKE '$c'";
     $query = mysql_query($sql,$d) or die(mysql_error());
     $v = mysql_fetch_row($query);
         return $v[0];
     return 'Table description not found';

echo table_description('table','col',$db);