L2 Info : PHP et Programmation Web
 
◃  Ch. 8 PHP et SGBD : l'API PostgreSQL  ▹
 

Description d'une table

  • pg_meta_data( resource $connection , string $table_name [, bool $extended ] ): array
  • Exemple :
      $tabDpt = pg_meta_data($ptrDB, 'departement', false);
      echo '<ul>';
      foreach ($tabDpt as $key => $val)  {
          echo "<li><b>$key</b> => (";
          foreach ($val as $k => $v)
              echo $k.'='.$v.',';
          echo ')</li>';
      }
      echo '</ul><br />';
      $tabReg = pg_meta_data($ptrDB, 'region', true);
      echo '<ul>';
      foreach ($tabReg as $key => $val)  {
          echo "<li><b>$key</b> => (";
          foreach ($val as $k => $v)
              echo $k.'='.$v.',';
          echo ')<li>';
      }
      echo '</ul>';
    
  • Résultat :
    • code => (num=1,type=varchar,len=-1,not null=,has default=,array dims=0,is enum=,)
    • nom => (num=2,type=varchar,len=-1,not null=,has default=,array dims=0,is enum=,)
    • population => (num=3,type=int4,len=4,not null=,has default=,array dims=0,is enum=,)
    • superficie => (num=4,type=int4,len=4,not null=,has default=,array dims=0,is enum=,)
    • region => (num=5,type=varchar,len=-1,not null=,has default=,array dims=0,is enum=,)

    • id_region => (num=1,type=varchar,len=-1,not null=1,has default=,array dims=0,is enum=,is base=1,is composite=,is pesudo=,description=,)
    • nom_region => (num=2,type=varchar,len=-1,not null=1,has default=,array dims=0,is enum=,is base=1,is composite=,is pesudo=,description=,)
    • nom_2016 => (num=3,type=varchar,len=-1,not null=1,has default=,array dims=0,is enum=,is base=1,is composite=,is pesudo=,description=,)