Source for file desc_tables.php

Documentation is available at desc_tables.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4.  * Examples how to show the fields of a given table.
  5.  * This example simply reads out all table names available for your schema,
  6.  * take the first shown table and calls the method "DescTable()" with the found
  7.  * tablename. Afterwards this table structure is dumped on screen.
  8.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  9.  * @package db_MySQL
  10.  * @subpackage Examples
  11.  * @version 0.37 (11-Jul-2009)
  12.  *  $Id: desc_tables.php,v 1.1 2009/07/11 18:00:42 siegel Exp $
  13.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  14.  * @filesource
  15.  */
  16. /**
  17.  */
  18. require('functions.inc.php');
  19. $db new db_MySQL('./dbdefs.inc.php');
  20. $d WhichBR();
  21. if($d['SAPI'!= 'cli')
  22.   {
  23.   echo("<pre>\n");
  24.   }
  25. $db->Connect();
  26.  
  27. // Retrieve the first available table:
  28.  
  29. $stmt $db->QueryResult('SHOW TABLES');
  30. while($table $db->FetchResult($stmt,MYSQL_NUM))
  31.   {
  32.   break;
  33.   }
  34. $db->FreeResult($stmt);
  35. if($table[0== '')
  36.   {
  37.   $db->Disconnect();
  38.   die('ERROR: No table found?? Please create at least one table to describe.'.$d['LF']);
  39.   }
  40. $tfields $db->DescTable($table[0]);
  41. printf('%sTable %s has %d fields:%s%s',$d['LF'],$table[0],count($tfields),$d['LF'],$d['LF']);
  42. print('Fieldname                        | Type/Size          | Flags'.$d['LF']);
  43. print('---------------------------------+--------------------+----------------------'.$d['LF']);
  44. for($i 0$i count($tfields)$i++)
  45.   {
  46.   $type $tfields[$i][DBOF_MYSQL_COLTYPE].'('.$tfields[$i][DBOF_MYSQL_COLSIZE].')';
  47.  
  48.   printf('%-32s | %-18s | %s%s',$tfields[$i][DBOF_MYSQL_COLNAME],
  49.                                 $type,
  50.                                 $tfields[$i][DBOF_MYSQL_COLFLAGS],
  51.                                 $d['LF']);
  52.   }
  53. echo($d['HR']);
  54. DBFooter($d['LF'],$db);
  55. $db->Disconnect();
  56. echo($d['LF']);
  57. ?>

Documentation generated on Sat, 07 Aug 2010 10:18:09 +0200 by phpDocumentor 1.4.3