1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <?php
class MaBase
{
public $conn = NULL;
public $hostname="localhost";
public $dbname="lcesa";
public $username="root";
public $pw="lcesa";
//constructeur vide ne contient aucun paramètre
public function __construct()
{
//$this->connect();
}
/**
* Renvoie une instance de connexion à la BD
*
* @return type PDO :une instance de connexion à la BD
*/
public function connect()
{
try {
$this->conn = new PDO ("mysql:host={$this->hostname};dbname={$this->dbname}",$this->username,$this->pw );
return $this->conn;
}
catch( PDOException $Exception ) {
echo "Echec connexion:",$Exception->getMessage();
}
}
}
// --------------------------------------Gestion des techniciens-------------------------------
class Technicien
{
public function doSelectById(Array $id)
{
// code select
}
public function doSelect()
{
$base = new MaBase();//
$sql = "SELECT * FROM technicien";
$sth = $base->connect()->prepare($sql);
$sth->execute();
$tab = $sth->fetchAll(PDO::FETCH_OBJ);
foreach ($tab as $row){
echo $row->Nom,'<br>';
}
} |