Jump to content

Pages vues


Recommended Posts

Voila j'ai un pus mettre en place un script PHP qui permet de faire le travail, faut juste que je l’intègre malheureusement je sais pas comment faire

<?php
    try {
         
        $conn= new PDO("mysql:dbname=counter;host=localhost" , "root", "",array(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION));
        $find_counts = null;
        $find_counts = $conn->query('SELECT counts FROM user_count');
        echo '<br>DEBUT WHILE';
         
        //cas d'un retour vide
        if (!is_null($find_counts) && $find_counts !== FALSE) {
            $row = $find_counts->fetch();
        }
         
        echo '<br>Cette page a été vue : '.$row['counts'];
        $update_count = "UPDATE user_count SET counts= counts + 1";
        $stmt = $conn->prepare($update_count);
        if (!$stmt->execute()) {
            echo '<br>ERREUR';
            throw PDOException('ERREUR PDO TUTU',100);
        } else {
            echo '<br>Compteur modifie';
        }
        echo '<br>FIN WHILE';
    } catch(PDOException $pdoE) {
        //CATCH ERREURS PDO
        die('Erreur:' .$pdoE->getMessage());
    } catch(Exception $e) {
        //CATCH TOUTE ERREURS
        die('Erreur:' .$e->getMessage());
    }
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...