ANNEXE
a
ECHANTILLONS DES CODE PRINCIPAL DU SYSTEME Connexion
à la Base de Données MySQL
<?php
session_start();
try {
$db = new
\PDO("mysql:host=localhost;dbname=_webcommunique"Ç"root"Ç"18001212");
} catch(Exception $e) {
exit('impossible to find a connexion');
}
?>
les fonctions
<?php
class Users{
private $db;
public function __construct($db){
if(!isset($_SESSION)){
session_start();
}
if(!isset($_SESSION['user'])){
$_SESSION['user']=array();
}
$this->db=$db;
}
public function login($id_user){
$select = $this->db->prepare("SELECT * FROM _admin
WHERE _id=:id");
$select->execute(array('id'=>$id_user));
$result =$select->fetch(PDO::FETCH_OBJ);
if ($result) {
$_SESSION['user']['user_id'] = $result->id;
$_SESSION['user']['user_nom'] = $result->_nom;
$_SESSION['user']['user_postnom'] =
$result->_postnom;
$_SESSION['user']['user_email'] = $result->_email;
$_SESSION['user']['user_password'] =
$result->_moddepasse;
$_SESSION['user']['niveau'] = 0;
$_SESSION['user']['security'] = true;
}
}
public function logout()
{
session_destroy();
}
}
function comptUser($db){
$re = $db->prepare('SELECT COUNT(*) FROM _admin');
$re->execute();
$re = $re->fetchColumn();
}
b
return (int)$re;
}
function comptEleve($db){
$re = $db->prepare('SELECT COUNT(*) FROM _eleve');
$re->execute();
$re = $re->fetchColumn();
return (int)$re;
}
function ComptCommunique($db){
$re = $db->prepare('SELECT COUNT(*) FROM
_communique');
$re->execute();
$re = $re->fetchColumn();
return (int)$re;
}
function countparent($db){
$re=$db->prepare('SELECT COUNT(*) from _parent');
$re->execute();
$re=$re->fetchColumn();
return(int)$re;
}
function comptecommunique($db){
$re=$db->prepare('SELECT COUNT(*) from
_communique');
$re->execute();
$re=$re->fetchColumn();
return(int)$re;
}
function comptVisitor($db){
$re = $db->prepare('SELECT _idUser FROM _visitor GROUP BY
_idUser');
$re->execute();
$re = $re->fetchAll();
return (int)(count($re));
}
function _addVisitedPage($cokkie,$page,$db){
$re = $db->prepare('INSERT INTO _visitor (_idUser, _page)
VALUES (?,?)');
$re->execute([$cokkie,$page]);
}
?>;
Les inclusions des pages en PHP
<?php require_once('includes/_base.php'); ?>
<?php include('./pages/_barleft.php') ?>
<?php include('./pages/_content_values.php') ?>
if ($myqwery) {
echo '<script>alert("Modification reussie
")</script';
}
else {
'data Not updated';
}
|