Valid XHTML    Valid CSS2    

Listing du fichier combienPDO.php

 

00001     <?php
00002     
# # (gH) -_- combienPDO.php ; TimeStamp (unix) : 27 Janvier 2021 vers 17:09
00003     
include("../std.php") ;
00004     
debutPage
(" fonction COMBIEN en PHP / PDO ") ;
00005     
h1
("Comptages ") ;
00006     
blockquote() ;
00007     
debutSection() ;
00008     
###################################################
00009     
00010     
function
combien_pas_terrible($bdd,$ndlb,$ndlt) {
00011     
00012      try {
00013     
$res
= $bdd->query("select count(*) from $ndlb.$ndlt ") ;
00014      } catch (
Exception $e) {
00015      echo
"Probleme combien : "
.$e->getMessage()."\n" ;
00016      die(
"STOP.\n") ;
00017      } ;
# fin de catch
00018     
$ldr
= $res->fetch(PDO::FETCH_ASSOC) ;
00019      echo
"
$ndlt : ".$ldr["count(*)"]." enregistrements." ;
00020     
00021     }
# fin function combien_pas_terrible
00022     
00023     ###################################################
00024     
00025     
function
combien($bdd,$ndlb,$ndlt) {
00026     
00027     
$cha
= "count(*)";
00028     
$req
= "select $cha from $ndlb.$ndlt " ;
00029      try {
00030     
$res
= $bdd->query("$req") ;
00031      } catch (
Exception $e) {
00032      echo
"Probleme combien : "
.$e->getMessage()."\n" ;
00033      die(
"STOP.\n") ;
00034      } ;
# fin de catch
00035     
00036     
$ldr
= $res->fetch(PDO::FETCH_ASSOC) ;
00037     
$nbe
= $ldr[$cha] ;
00038     
00039      return(
$nbe ) ;
00040     
00041     }
# fin function combien
00042     
00043     ###################################################
00044     
00045     
$bdd
= new PDO("mysql:localhost;dbname=statdata","anonymous","anonymous") or die ("probleme connexion") ;
00046     
$bdd
-> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION) ;$bdd-> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION) ;
00047     
00048     
combien_pas_terrible
($bdd,"statdata","elf") ;
00049     
br() ; ;
00050     
combien_pas_terrible
($bdd,"statdata","titanic") ;
00051     
br() ; ;
00052     
combien_pas_terrible
($bdd,"statdata","ronfle") ;
00053     
br() ;
00054     
00055     
###################################################
00056     
00057     
$tab
= "ronfle" ;
00058     
$nbe
= combien($bdd,"statdata",$tab) ;
00059     echo
" il y a
$nbe enregistrements dans $tab " ;
00060     
00061     
###################################################
00062     
00063     
finSection() ;
00064     
finblockquote() ;
00065     
finPage() ;
00066     
?>

Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.

 

 

retour gH    Retour à la page principale de   (gH)