begin process at 2012 05 27 19:05:30
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Base de données

 > LISTE DES CHAMPS ET STRUCTURE D'UNE TABLE SQLITE (PHP 5)

LISTE DES CHAMPS ET STRUCTURE D'UNE TABLE SQLITE (PHP 5)


 Information sur la source

Note :
Aucune note
Catégorie :Base de données Niveau :Débutant Date de création :17/10/2004 Date de mise à jour :17/10/2004 15:39:58 Vu :10 672

Auteur : frop01

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Une simple requête sqlite : PRAGMA table_info('nomtable') , retourne la liste des champs de la table en question.

La liste retournée est composée d'un N°Ordre, Nom du champ, Type (longueur), Null ou not null (99 ou 0),Valeur par défaut,Clé primaire (1 ou 0)


Source

  • <?php
  • if ($db = sqlite_open('sqlitemanager/test.sqlite', 0666, $sqliteerror)) {
  • // extraire la liste des tables et leurs requete de creation à partir de la table interne de la base sqlite_master
  • $result = sqlite_query ($db, 'PRAGMA table_info(\'essai\')');
  • $tab= array();
  • echo "<table border=1 width=100%>";
  • // ***********DEBUT AFFICHAGE ENTETE TABLEAU *********************************
  • echo "<tr bgcolor=#C0C0C0 align=center>";
  • echo "<td width=10%>N°Ordre</td>";
  • echo "<td width=30%>Nom du champ</td>";
  • echo "<td width=20%>Type et longueur</td>";
  • echo "<td width=10%>Not Null</td>";
  • echo "<td width=20%>Valeur par défaut</td>";
  • echo "<td width=10%>Index</td>";
  • echo "</tr>";
  • // ***********FIN AFFICHAGE ENTETE TABLEAU *********************************
  • while ($row = sqlite_fetch_array($result)) { // extraire les données dans un tableau
  • echo "<tr>";
  • echo "<td width=10%>$row[0]</td>"; // afficher n° d'ordre
  • echo "<td width=30%>$row[1]</td>"; // afficher nom du champs
  • echo "<td width=20%>$row[2]</td>"; // afficher type et longueur
  • if ($row[3]=='99') {
  • echo "<td width=10%>Not null</td>"; // afficher Not null
  • }
  • else
  • {
  • echo "<td width=10%>Null</td>"; // afficher Not null
  • }
  • if ($row[4]!="") { // tester si la valeur n'est pas vide
  • echo "<td width=20%>$row[4]</td>"; // afficher defaut
  • }
  • else
  • {
  • echo "<td width=20%>&nbsp;</td>";
  • }
  • if ($row[5]=='1') {
  • echo "<td width=10%>Primaire</td>"; // afficher clé primaire ou pas
  • }
  • else
  • {
  • echo "<td width=10%>&nbsp;</td>";
  • }
  • $tab[] = $row;
  • echo "</tr>";
  • }
  • echo " </table>";
  • echo "<br><br>";
  • echo "Nombre de champs : ".count($tab); // afficher le nombre d'enregistrements
  • } else {
  • die($sqliteerror);
  • }
  • ?>
<?php

if ($db = sqlite_open('sqlitemanager/test.sqlite', 0666, $sqliteerror)) {
  // extraire la liste des tables et leurs requete de creation à partir de la table interne de la base sqlite_master
    $result = sqlite_query ($db, 'PRAGMA table_info(\'essai\')');
    $tab= array();
    echo "<table border=1 width=100%>";

 // ***********DEBUT AFFICHAGE ENTETE TABLEAU *********************************
    echo "<tr bgcolor=#C0C0C0 align=center>";
    echo "<td width=10%>N°Ordre</td>";
    echo "<td width=30%>Nom du champ</td>";
    echo "<td width=20%>Type et longueur</td>";
    echo "<td width=10%>Not Null</td>";
    echo "<td width=20%>Valeur par défaut</td>";
    echo "<td width=10%>Index</td>";
    echo "</tr>";
 // ***********FIN AFFICHAGE ENTETE TABLEAU *********************************

    while ($row = sqlite_fetch_array($result)) {  // extraire les données dans un tableau
    echo "<tr>";
    echo "<td width=10%>$row[0]</td>"; // afficher n° d'ordre
    echo "<td width=30%>$row[1]</td>"; // afficher nom du champs
    echo "<td width=20%>$row[2]</td>"; // afficher type et longueur
    if ($row[3]=='99') {
      echo "<td width=10%>Not null</td>"; // afficher Not null
     }
    else
    {
      echo "<td width=10%>Null</td>"; // afficher Not null
    }
    if ($row[4]!="") {    // tester si la valeur n'est pas vide
       echo "<td width=20%>$row[4]</td>"; // afficher defaut
    }
    else
    {
       echo "<td width=20%>&nbsp;</td>";
    }
    if ($row[5]=='1')  {
        echo "<td width=10%>Primaire</td>"; // afficher clé primaire ou pas
    }
    else
    {
       echo "<td width=10%>&nbsp;</td>";
    }
    $tab[] = $row;
    echo "</tr>";

 }
echo " </table>";
echo "<br><br>";
echo "Nombre de champs : ".count($tab);     // afficher le nombre d'enregistrements


} else {
    die($sqliteerror);
}

?>



 Historique

17 octobre 2004 15:39:59 :
Correction au niveau de l'othographe

 Sources du même auteur

Source avec une capture PROGRESSBAR (BARRE DE PROGRESSION AVEC AFFICHAGE DU POURCENT...
DÉTERMINER LA TAILLE D'UN BASE DE DONNÉES MYSQL ET LE NOMBRE...
LISTE DES TABLES ET STRUCTURE D'UNE BASE DE DONNÉES SQLITE (...
Source avec Zip BASE DE DONNÉES SQLITE SOUS PHP 4
AFFICHER UNE LISTE DÉROULANTE EN FONCTION D'UNE AUTRE LISTE ...

 Sources de la même categorie

Source avec Zip ORM : DAO, ACTIVERECORD ET DBLIST par Reldan
Source avec une capture CET EXTRAIT PERMET D'AJOUTER DANS UN TABLEAU UNE AGRÉGATION ... par Denis007
EXPORT DE BASE AU FORMAT CSV par remib74
Source avec Zip RECHERCHE DES DOUBLONS DANS UNE TABLE MYSQL EN SÉLECTIONNANT... par aladec2007
[CRON] INSERT ON DUPLICATE KEY UPDATE par pierreSabatier

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,515 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales