onfinfra
This commit is contained in:
23
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/BucheronSQL.php
Normal file
23
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/BucheronSQL.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class BucheronSQL {
|
||||
|
||||
private $_laConnexion;
|
||||
|
||||
function __construct() {
|
||||
$this->_laConnexion = new Connexion();
|
||||
}
|
||||
|
||||
function readAllBucheron() {
|
||||
$stmt = $this->_laConnexion->dbh()->prepare("SELECT id, nom, prenom FROM bucheron");
|
||||
$valid = $stmt->execute();
|
||||
if (!$valid) {
|
||||
$this->_laConnexion->afficherErreurSQL("Erreur recherche bucherons");
|
||||
}
|
||||
// Parcours du jeu d'enregistrement
|
||||
//Retourne dans un array
|
||||
$tabBuchron = array("lesBucherons" => $stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
return $tabBuchron;
|
||||
}
|
||||
|
||||
}
|
42
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/Connexion.php
Normal file
42
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/Connexion.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of Connexion *
|
||||
* @author Dominique_2
|
||||
*/
|
||||
class Connexion {
|
||||
|
||||
private $_dbh; // Chaine de connexion
|
||||
|
||||
/**
|
||||
* Connexion persistante au serveur
|
||||
* @return \PDO Connexion
|
||||
*/
|
||||
public function __construct(){
|
||||
// Définition des variables de connexion
|
||||
$user = "adminbdarbre";
|
||||
$pass = "mdpbdarbre";
|
||||
$dsn ='mysql:host=localhost;dbname=bdarbre'; //Data Source Name
|
||||
|
||||
// Connexion
|
||||
try {
|
||||
$this->_dbh = new PDO($dsn, $user, $pass, array(PDO::ATTR_PERSISTENT=>true,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); // Connexion persistante
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
die("Erreur : " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
/** afficherErreurSQL :
|
||||
* Affichage de messages lors l'accès à la bdd avec une requete SQL
|
||||
* @param $message : message a afficher
|
||||
*/
|
||||
function afficherErreurSQL($message, $sql="") {
|
||||
echo $message . "<br />" . $sql . "<br />";
|
||||
$info = $this->_dbh->errorInfo();
|
||||
echo "Code erreur : " . $info[0] . ", Message : " . $info[2];
|
||||
die();
|
||||
}
|
||||
function dbh() {
|
||||
return $this->_dbh;
|
||||
}
|
||||
}
|
34
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/EspeceSQL.php
Normal file
34
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/EspeceSQL.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of EspeceSQL
|
||||
*
|
||||
* @author pierre.perdigues
|
||||
*/
|
||||
class EspeceSQL {
|
||||
|
||||
private $_laConnexion;
|
||||
|
||||
function __construct() {
|
||||
$this->_laConnexion = new Connexion();
|
||||
}
|
||||
|
||||
function readEspeceAddr($adresse) {
|
||||
$stmt = $this->_laConnexion->dbh()->prepare("SELECT DISTINCT libelle FROM espece INNER JOIN arbre ON espece.id = arbre.idEspece WHERE arbre.idAdresse=:adr");
|
||||
$stmt->bindValue(':adr', $adresse);
|
||||
$valid = $stmt->execute();
|
||||
if (!$valid) {
|
||||
$this->_laConnexion->afficherErreurSQL("Erreur recherche espece");
|
||||
}
|
||||
//Retourne dans un array
|
||||
$tabEspece = array("lesEspeces" => $stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
return $tabEspece;
|
||||
}
|
||||
|
||||
}
|
34
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/SecteurSQL.php
Normal file
34
AP4/onfinfra/sv/sauvegardephp/Bucheron/bdd/SecteurSQL.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of SecteurSQL
|
||||
*
|
||||
* @author pierre.perdigues
|
||||
*/
|
||||
class SecteurSQL {
|
||||
|
||||
private $_laConnexion;
|
||||
|
||||
function __construct() {
|
||||
$this->_laConnexion = new Connexion();
|
||||
}
|
||||
|
||||
function readAllSecteur() {
|
||||
$stmt = $this->_laConnexion->dbh()->prepare("SELECT * FROM adresse");
|
||||
$valid = $stmt->execute();
|
||||
if (!$valid) {
|
||||
$this->_laConnexion->afficherErreurSQL("Erreur recherche bucherons");
|
||||
}
|
||||
// Parcours du jeu d'enregistrement
|
||||
//Retourne dans un array
|
||||
$tabSecteur = array("lesSecteurs" => $stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
return $tabSecteur;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user