retrieving table comment from mysql database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • windandwaves

    retrieving table comment from mysql database

    Hi Gurus

    Is there a way to retrieve the table comment from a mysql table.

    In PHP My Admin, you can set the comment for a table. however, I was
    wondering if you can retrieve it for use in a PHP page.

    Any help greatly appreciated.

    - Nicolaas


  • J.O. Aho

    #2
    Re: retrieving table comment from mysql database

    windandwaves wrote:[color=blue]
    > Hi Gurus
    >
    > Is there a way to retrieve the table comment from a mysql table.
    >
    > In PHP My Admin, you can set the comment for a table. however, I was
    > wondering if you can retrieve it for use in a PHP page.
    >
    > Any help greatly appreciated.[/color]

    Comment saved in a PHP_My_Admin table.

    Comment

    • Gordon Burditt

      #3
      Re: retrieving table comment from mysql database

      >Is there a way to retrieve the table comment from a mysql table.[color=blue]
      >
      >In PHP My Admin, you can set the comment for a table. however, I was
      >wondering if you can retrieve it for use in a PHP page.
      >
      >Any help greatly appreciated.[/color]

      In PHP 5.0.x, it's in information_sch ema.tables.tabl e_comment .

      It's also in SHOW CREATE TABLE in PHP 5.0.x and earlier versions.

      Gordon L. Burditt

      Comment

      • NC

        #4
        Re: retrieving table comment from mysql database

        windandwaves wrote:[color=blue]
        >
        > Is there a way to retrieve the table comment from
        > a mysql table.[/color]

        Yes. Run a SHOW CREATE TABLE query on the table you want
        to see the comment for. For example, if you have a table
        called `example`, the query will be:

        SHOW CREATE TABLE example;

        It will return a CREATE TABLE statement for the table,
        which will include the comment. You will need to parse
        it out of the CREATE TABLE statement.

        Cheers,
        NC

        Comment

        • windandwaves

          #5
          Re: retrieving table comment from mysql database

          NC wrote:[color=blue]
          > windandwaves wrote:[color=green]
          >>
          >> Is there a way to retrieve the table comment from
          >> a mysql table.[/color]
          >
          > Yes. Run a SHOW CREATE TABLE query on the table you want
          > to see the comment for. For example, if you have a table
          > called `example`, the query will be:
          >
          > SHOW CREATE TABLE example;
          >
          > It will return a CREATE TABLE statement for the table,
          > which will include the comment. You will need to parse
          > it out of the CREATE TABLE statement.
          >[/color]

          Thank you for clarifying this.

          - Nicolaas


          Comment

          • windandwaves

            #6
            Re: retrieving table comment from mysql database

            windandwaves wrote:[color=blue]
            > Hi Gurus
            >
            > Is there a way to retrieve the table comment from a mysql table.
            >
            > In PHP My Admin, you can set the comment for a table. however, I was
            > wondering if you can retrieve it for use in a PHP page.
            >
            > Any help greatly appreciated.
            >
            > - Nicolaas[/color]

            This is the function I made up (I only use one space as indent):

            function table_descripti on($t) {
            $sql = 'SHOW CREATE TABLE `'.$t.'`;';
            $query = mysql_query($sq l);
            $v = mysql_result($q uery, 0, 1);
            if($v) {
            $p = strpos($v,"COMM ENT=");
            if($p) {
            return substr($v, $p + 8);
            }
            }
            return 'Table description not found';
            }


            Comment

            Working...