title: How can I get the type, length and comment about columns in MySQL database using PDO?
body: <p>I have created this function to get information about the tables, and their corresponding columns, in my MySQL database:</p>
  
  <pre><code>class SQL extends DB
  {
      public static function showTables($alias='', $table_name='')
      {
          if(empty($alias) || $alias===true){  //  empty = show all tables from all available connections, true = show columns aswell
              foreach(self::get() as $con){  //  get() keeps, among other things, the aliases of all available connections
                  $html .= '"'.$con['alias'].'": '.$con['db'];  //  the alias for the connection, and databasename, for the following table(s)
                  $tables = self::con($con['alias'])-&gt;query('SHOW TABLES')-&gt;fetchAll(PDO::FETCH_COLUMN);  //  fetch an array of all tables available through this connection
                  foreach($tables as $table){
                      $html .= $table;  //  table name
                      if($alias===true){  //  show columns aswell when this is set to true
                          $columns = self::con($con['alias'])-&gt;query('SHOW COLUMNS FROM '.$table)-&gt;fetchAll(PDO::FETCH_COLUMN);  //  fetch an array of all column in this table
                          foreach($columns as $column){
                              $html .= $column;  //  column name
                          }
                      }
                  }
              }
          } else {
              /*  basically the same code, but limits the result to a defined connection. And table if that is defined  */
          }
      }
  }
  </code></pre>
  
  <p>It's important to know that this function is tailored to the way I set and use the PDO connections. Basically each connection has an alias, and the connection is accessed trough the given alias. But that has nothing to do with my issue.</p>
  
  <p>Here's how I use the function, and what it produces:</p>
  
  <pre><code>&lt;?=sql::showTables(true)?&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/I0G2J.png" alt="enter image description here"><br>
  <em>(I've removed all the css-styling from the code above)</em></p>
  
  <p>This is ok. But I would also like to get, at least, the type, lenght and comment (if any).</p>
  
  <p>I just tried, when I was writing this question, to put the <code>getColumnMeta()</code> inside the column <code>foreach</code>-loop, but that didn't work quite as expected:</p>
  
  <pre><code>    $columns = self::con($con['alias'])-&gt;query('SHOW COLUMNS FROM '.$table)-&gt;getColumnMeta(0);
      foreach($columns as $column){
          $meta = self::con($con['alias'])-&gt;query('SELECT `'.$column.'` FROM '.$table)-&gt;getColumnMeta(0);
          $html .= $meta['name'].' '.$meta['native_type'].'('.$meta['len'].')';
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/lW6rh.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/OEdzw.png" alt="enter image description here"></p>
  
  <p>You can see the difference..<br>
  Does anyone know of another method for this? getting the type, lenght and comment.  </p>
  
  <p>Thanks in advance.</p>