le moment ou j'ai cassé le auto increment

main
thchazot1 2 years ago
parent 8d11ae96f8
commit 4cb7ea559f

@ -0,0 +1,33 @@
<?php
class Connection extends PDO {
private $stmt;
public function __construct(string $dsn, string $username, string $password) {
parent::__construct($dsn,$username,$password);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
/** * @param string $query
* @param array $parameters *
* @return bool Returns `true` on success, `false` otherwise
*/
public function executeQuery(string $query, array $parameters = []) : bool{
$this->stmt = parent::prepare($query);
foreach ($parameters as $name => $value) {
$this->stmt->bindValue($name, $value[0], $value[1]);
}
return $this->stmt->execute();
}
public function getResults() : array {
return $this->stmt->fetchall();
}
}
?>

@ -0,0 +1,40 @@
<html>
<body>
<?php
require_once("connection.php");
require_once('tacheGateway.php');
//A CHANGER
$user= 'thchazot1';
$pass='achanger';
$dsn='mysql:host=localhost;dbname=dbthchazot1';
$id=468;
$name='LALALILALOU';
$content='Argent, Encore de l\'argent';
try{
$con=new Connection($dsn,$user,$pass);
$t=new Tache($id, $name, $content, FALSE);
$gateway=new TacheGateway($con);
$gateway->insert($t, 1);
$tabTache=$gateway->getTacheFromIdList(1);
foreach($tabTache as $tache){
print($tache);
echo "<br>";
}
}
catch( PDOException $Exception ) {
echo 'erreur';
echo $Exception->getMessage();
}
?>
</body>
</html>

@ -0,0 +1,62 @@
<?php
require_once('user.php');
require_once('tache.php');
class Liste
{
private $id;
private $name;
private $private;
private $creator;
private $taches;
function __construct( int $id, string $name, boolean $private, User $creator, array $taches)
{
$this->id=$id;
$this->name=$name;
$this->$creator=$creator;
$this->$taches=$taches;
}
public function __toString()
{
return $this->id . " " . $this->name . " " . $this->creator;
}
public function getId(){
return $id;
}
public function getName(){
return $name;
}
public function getCreator(){
return $creator;
}
public function getTaches(){
return $taches;
}
public function setName(string $name){
$this->name=$name;
}
public function setPrivate(boolean $private){
$this->private=$private;
}
public function setCreator(string $creator){
$this->creator=$creator;
}
public function setTaches(array $taches){
$this->taches=$taches;
}
}
?>

@ -31,4 +31,4 @@
</a></address> </a></address>
</body> </body>
</html> </html>

@ -0,0 +1,55 @@
<?php
require_once('user.php');
class Tache
{
private $id;
private $name;
private $content;
private $completed;
function __construct( int $id, string $name, string $content, bool $completed)
{
$this->id=$id;
$this->name=$name;
$this->content=$content;
$this->completed=$completed;
}
public function __toString()
{
return $this->id . " " . $this->name . " " . $this->content . " " . $this->completed;
}
public function getId(){
return $this->id;
}
public function getName(){
return $this->name;
}
public function getContent(){
return $this->content;
}
public function getCompleted(){
return $this->completed;
}
public function setName(string $name){
$this->name=$name;
}
public function setContent(string $content){
$this->content=$content;
}
public function setCompleted(bool $completed){
$this->completed=$completed;
}
}
?>

@ -0,0 +1,47 @@
<?php
require_once('tache.php');
class TacheGateway
{
private $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(Tache $t, int $idList): void{
$query = "INSERT INTO Tache VALUES (null, :name, :content, :completed, :idList)";
$this->con->executeQuery($query, array(':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL), ':idList' => array($idList, PDO::PARAM_INT)));
}
public function getTacheFromIdList(int $id): array{
$tabTaches=[];
$query = "SELECT * FROM Tache t where idListe=:id";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
$results=$this->con->getResults();
foreach ($results as $row) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content'], $row['completed']);
}
return $tabTaches;
}
/*
public function findByName(string $name): array{
if (!empty($name)){
$query = "SELECT * FROM Tache WHERE name=:name";
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
$results=$con->getResults();
foreach ($results as $row ) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content']);
}
return $tabTaches;
}
}
*/
}
?>

@ -0,0 +1,38 @@
<?php
class Utilisateur
{
private $id;
private $username;
private $password;
function __construct( int $id, string $username, string $password)
{
$this->id=$id;
$this->username=$username;
$this->password=$password;
}
public function __toString()
{
return $this->id . " " . $this->username . " " . $this->contenu;
}
public function getId(){
return $id;
}
public function getUsername(){
return $username;
}
public function getPassword(){
return $password;
}
public function setUsername(string $username){
$this->username=$username;
}
}
?>

@ -0,0 +1,42 @@
<html>
<body>
test
<?php
require_once("connection.php");
require_once('tacheGateway.php');
require_once('tache.php');
/*
//A CHANGER
$user= 'thchazot1';
$pass='achanger';
$dsn='mysql:host=localhost;dbname=dbthchazot1';
try{
$con=new Connection($dsn,$user,$pass);
$t=new Tache($id, $name, $content);
$gateway=new TacheGateway($con);
$gateway->insert($t);
$query = "SELECT * FROM Tache";
$con->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
$results=$con->getResults();
Foreach($results as $row){
echo ($row['id']. " | ". $row['name'] . " | ". $row['content'] . "<br><br>");
}
}
catch( PDOException $Exception ) {
echo 'erreur';
echo $Exception->getMessage();
}
?*/
?>
</body>
</html>
Loading…
Cancel
Save