Listing du fichier combienPhp7.php avec syntaxhighlighter
<?php ################################################### function combien($ndlt) { ################################################### $bdd = new PDO("mysql:localhost;dbname=statdata","anonymous","anonymous") or die ("probleme connexion") ; $bdd-> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION) ;$bdd-> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION) ; $ndlb = "statdata" ; $cha = "count(*)"; $req = "select $cha from $ndlb.$ndlt " ; try { $res = $bdd->query("$req") ; } catch (Exception $e) { echo "Probleme combien : ".$e->getMessage()."\n" ; die("STOP.\n") ; } ; # fin de catch $ldr = $res->fetch(PDO::FETCH_ASSOC) ; $nbe = $ldr[$cha] ; return( $nbe ) ; } # fin function combien ################################################### ## programme principal : # un peu court : echo " v1 il y a ".combien("elf")." enregistrements dans elf.\n" ; # mieux : $nbe = combien("elf") ; echo " v2 il y a $nbe enregistrements dans elf\n" ; # encore mieux : $tab = "elf" ; $nbe = combien($tab) ; echo " v3 il y a $nbe enregistrements dans $tab.\n" ; ################################################### ?>La coloration syntaxique est réalisée par : SyntaxHighlighter.
Si vous préférez, vous pouvez utiliser celle de geshi ou même celle construite autour de la fonction highlight_file.
Retour à la page principale de (gH)