aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--class/class.app.php108
-rw-r--r--class/class.art.php8
-rw-r--r--public/index.php40
-rw-r--r--public/w/index.php56
4 files changed, 137 insertions, 75 deletions
diff --git a/class/class.app.php b/class/class.app.php
index 056e65b..d9867d3 100644
--- a/class/class.app.php
+++ b/class/class.app.php
@@ -4,69 +4,79 @@ class App
{
private $bdd;
- public function __construct()
+ public function __construct($config)
{
- // try {
- // $this->bdd = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'] . ';charset=utf8', $config['user'], $config['password']);
- // } catch (Exeption $e) {
- // die('Erreur : ' . $e->getMessage());
- // }
-
try {
- $this->bdd = new PDO('mysql:host=localhost;dbname=wcms;charset=utf8', 'root', '');
+ $this->bdd = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'] . ';charset=utf8', $config['user'], $config['password']);
} catch (Exeption $e) {
die('Erreur : ' . $e->getMessage());
}
+
+ // try {
+ // $this->bdd = new PDO('mysql:host=localhost;dbname=wcms;charset=utf8', 'root', '');
+ // } catch (Exeption $e) {
+ // die('Erreur : ' . $e->getMessage());
+ // }
}
public function add(Art $art)
{
-// tester l'existence de l'id
- $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
-
- $q = $this->bdd->prepare('INSERT INTO art(id, titre, soustitre, intro, tag, datecreation, datemodif, css, html, secure, couleurtext, couleurbkg, couleurlien) VALUES(:id, :titre, :soustitre, :intro, :tag, :datecreation, :datemodif, :css, :html, :secure, :couleurtext, :couleurbkg, :couleurlien)');
- $q->bindValue(':id', $art->id());
- $q->bindValue(':titre', $art->titre());
- $q->bindValue(':soustitre', $art->soustitre());
- $q->bindValue(':intro', $art->intro());
- $q->bindValue(':tag', $art->tag());
- $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
- $q->bindValue(':css', $art->css());
- $q->bindValue(':html', $art->html());
- $q->bindValue(':secure', $art->secure());
- $q->bindValue(':couleurtext', $art->couleurtext());
- $q->bindValue(':couleurbkg', $art->couleurbkg());
- $q->bindValue(':couleurlien', $art->couleurlien());
-
- $q->execute();
+ if ($this->exist($art->id())) {
+ echo '<p>cet id existe deja</p>';
+ } else {
+
+ $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
+
+ $q = $this->bdd->prepare('INSERT INTO art(id, titre, soustitre, intro, tag, datecreation, datemodif, css, html, secure, couleurtext, couleurbkg, couleurlien) VALUES(:id, :titre, :soustitre, :intro, :tag, :datecreation, :datemodif, :css, :html, :secure, :couleurtext, :couleurbkg, :couleurlien)');
+
+ $q->bindValue(':id', $art->id());
+ $q->bindValue(':titre', $art->titre());
+ $q->bindValue(':soustitre', $art->soustitre());
+ $q->bindValue(':intro', $art->intro());
+ $q->bindValue(':tag', $art->tag());
+ $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s'));
+ $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
+ $q->bindValue(':css', $art->css());
+ $q->bindValue(':html', $art->html());
+ $q->bindValue(':secure', $art->secure());
+ $q->bindValue(':couleurtext', $art->couleurtext());
+ $q->bindValue(':couleurbkg', $art->couleurbkg());
+ $q->bindValue(':couleurlien', $art->couleurlien());
+
+ $q->execute();
+ }
}
public function delete(Art $art)
{
- $this->bdd->exec('DELETE FROM art WHERE id = ' . $art->id());
+ $req = $this->bdd->prepare('DELETE FROM art WHERE id = :id ');
+ $req->execute(array('id' => $art->id()));
+ $req->closeCursor();
}
public function get($id)
{
- $q = $this->bdd->query('SELECT * FROM art WHERE id = ' . $id);
- $donnees = $q->fetch(PDO::FETCH_ASSOC);
+ $req = $this->bdd->prepare('SELECT * FROM art WHERE id = :id ');
+ $req->execute(array('id' => $id));
+ $donnees = $req->fetch(PDO::FETCH_ASSOC);
return new Art($donnees);
+
+ $req->closeCursor();
+
}
public function getlist()
{
- $listart = [];
+ $list = [];
- $q = $this->bdd->query('SELECT titre, soustitre, intro FROM art ORDER BY titre');
-
- while ($donnees = $q->fetch(PDO::FETCH_ASSOC)) {
- $listart[] = new art($donnees);
+ $req = $this->bdd->query('SELECT * FROM art ORDER BY id');
+ while ($donnees = $req->fetch(PDO::FETCH_ASSOC))
+ {
+ $list[] = new Art($donnees);
}
-
- return $listart;
+ return $list;
}
public function count()
@@ -74,33 +84,33 @@ class App
return $this->bdd->query('SELECT COUNT(*) FROM art')->fetchColumn();
}
- // public function exist($id)
- // {
- // $r = $this->bdd->query('SELECT COUNT(*) AS art FROM art WHERE id = '.$id);
- // return $donnees = $r->fetch(PDO::FETCH_ASSOC);
- // }
-
public function exist($id)
{
- return $this->bdd->query('SELECT COUNT(*) FROM art WHERE id = ' . $id)->fetchColumn();
+ $req = $this->bdd->prepare('SELECT COUNT(*) FROM art WHERE id = :id ');
+ $req->execute(array('id' => $id));
+ $donnees = $req->fetch(PDO::FETCH_ASSOC);
+
+ return (bool)$donnees['COUNT(*)'];
}
public function update(Art $art)
{
- $q = $this->bdd->prepare('UPDATE art SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, cass = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien WHERE id = :id');
+ $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
+
+ $q = $this->bdd->prepare('UPDATE art SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, css = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien WHERE id = :id');
$q->bindValue(':id', $art->id());
$q->bindValue(':titre', $art->titre());
$q->bindValue(':soustitre', $art->soustitre());
$q->bindValue(':intro', $art->intro());
$q->bindValue(':tag', $art->tag());
- $q->bindValue(':datecreation', $art->datecreation());
- $q->bindValue(':datemodif', $art->datemodif());
+ $q->bindValue(':datecreation', $art->datecreation()->format('Y-m-d H:i:s'));
+ $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
$q->bindValue(':css', $art->css());
$q->bindValue(':html', $art->html());
$q->bindValue(':secure', $art->secure(), PDO::PARAM_INT);
- $q->bindValue(':couleurtext', $art->tag());
- $q->bindValue(':couleurbkgt', $art->couleurbkgt());
+ $q->bindValue(':couleurtext', $art->couleurtext());
+ $q->bindValue(':couleurbkg', $art->couleurbkg());
$q->bindValue(':couleurlien', $art->couleurlien());
$q->execute();
diff --git a/class/class.art.php b/class/class.art.php
index a94b649..ec085d8 100644
--- a/class/class.art.php
+++ b/class/class.art.php
@@ -182,14 +182,14 @@ class Art
public function setsecure($secure)
{
if ($secure >= 0 and $secure <= self::$securemax) {
- $this->secure = $secure;
+ $this->secure = intval($secure);
}
}
public function setcouleurtext($couleurtext)
{
$couleurtext = strval($couleurtext);
- if (strlen($couleurtext) < self::$lencouleur) {
+ if (strlen($couleurtext) <= self::$lencouleur) {
$this->couleurtext = strip_tags(trim($couleurtext));
}
}
@@ -197,7 +197,7 @@ class Art
public function setcouleurbkg($couleurbkg)
{
$couleurbkg = strval($couleurbkg);
- if (strlen($couleurbkg) < self::$lencouleur) {
+ if (strlen($couleurbkg) <= self::$lencouleur) {
$this->couleurbkg = strip_tags(trim($couleurbkg));
}
}
@@ -205,7 +205,7 @@ class Art
public function setcouleurlien($couleurlien)
{
$couleurlien = strval($couleurlien);
- if (strlen($couleurlien) < self::$couleurlien) {
+ if (strlen($couleurlien) <= self::$lencouleur) {
$this->couleurlien = strip_tags(trim($couleurlien));
}
}
diff --git a/public/index.php b/public/index.php
index 90df7d7..9b8a61b 100644
--- a/public/index.php
+++ b/public/index.php
@@ -4,22 +4,48 @@
<?php
-var_dump(__FILE__);
+try
+{
+ $bdd = new PDO('mysql:host=localhost;dbname=wcms;charset=utf8', 'root', '');
+}
+catch(Exception $e)
+{
+ die('Erreur : '.$e->getMessage());
+}
-$htdocs = str_replace(basename(__FILE__), __FILE__, '');
+// $reponse = $bdd->query('SELECT nom, age FROM art2 WHERE nom = \'eddie\'');
-var_dump($htdocs);
+// while ($donnees = $reponse->fetch())
+// {
+// echo $donnees['nom'] . ' a ' . $donnees['age'] . ' ANS<br />';
+// }
-var_dump($_SERVER["DOCUMENT_ROOT"]);
+// $reponse->closeCursor();
+// $req = $bdd->prepare('SELECT nom, age FROM art2 WHERE age = 23 ');
+// $req->execute(array($_GET['possesseur'], $_GET['prix_max']));
-set_include_path('e:/WEB/wcms');
+// echo '<ul>';
+// while ($donnees = $req->fetch())
+// {
+// echo '<li>' . $donnees['nom'] . ' (' . $donnees['prix'] . ' EUR)</li>';
+// }
+// echo '</ul>';
-echo get_include_path();
+// $req->closeCursor();
+$req = $bdd->prepare('SELECT * FROM art WHERE id = :id ');
+$req->execute(array('id' => 'articlet'));
+echo '<ul>';
+while ($donnees = $req->fetch())
+{
+ echo '<li>' . $donnees['titre'] . ' (' . $donnees['id'] . ' ANS)</li>';
+}
+echo '</ul>';
+
+$req->closeCursor();
-include('fn/fn.php');
?> \ No newline at end of file
diff --git a/public/w/index.php b/public/w/index.php
index 85c0902..4d28510 100644
--- a/public/w/index.php
+++ b/public/w/index.php
@@ -8,7 +8,7 @@ require('fn/fn.php');
require('class/class.art.php');
require('class/class.app.php');
$config = include('config.php');
-$app = new App();
+$app = new App($config);
session();
@@ -26,6 +26,25 @@ head('article');
// 'datemodif' => new DateTimeImmutable(null, timezone_open("Europe/Paris"))
// ]);
+$arraytest = ([
+ 'id' => 'articlet2',
+ 'titre' => 'titre',
+ 'soustitre' => 'soustitre',
+ 'intro' => 'intro',
+ 'tag' => 'sans tag,',
+ 'datecreation' => '2018-03-17 18:31:34',
+ 'datemodif' => '2018-03-17 18:31:34',
+ 'css' => 'display: inline:',
+ 'html' => 'coucou les loulous',
+ 'secure' => 0,
+ 'couleurtext' => '#000000',
+ 'couleurbkg' => '#ffffff',
+ 'couleurlien' => '#2a3599'
+]);
+
+// $art = new Art($arreytest);
+
+
// echo '<pre>';
// print_r($art);
// print_r($app);
@@ -37,25 +56,32 @@ head('article');
// echo '<p>article exist :' . $app->exist('articlet') . '</p>';
// var_dump($app->exist('articlet'));
-// $app->get('articlet');
-// echo '<pre>';
-// print_r($art);
-// print_r($app);
-// echo '</pre>';
-try {
- $bdd = new PDO('mysql:host=localhost;dbname=wcms;charset=utf8', 'root', '');
-} catch (Exeption $e) {
- die('Erreur : ' . $e->getMessage());
-}
+echo '<pre>';
+$art = $app->get('articlet');
+
+var_dump($art);
+
+echo 'count : ' . $app->count();
+
+ var_dump($app->exist('bouffffe'));
+ var_dump($app->exist('bouffe'));
+
+
+ $art2 = new Art($arraytest);
+
+// $app->add($art2);
+
+$app->update($art2);
+
+var_dump($app->getlist());
+
+echo '</pre>';
+
-$q = $bdd->query('SELECT * FROM art WHERE id = articlet');
-$donnees = $q->fetch();
-var_dump($donnees);
-$q = closeCursor();