Example #1
0
 public function __construct()
 {
     $this->pdo = Connect::getDB();
     if (empty($this->pdo)) {
         die('no database connection...');
     }
     if (empty($this->table)) {
         die('table name is null, you must set a table name into Entity model...');
     }
 }
Example #2
0
<?php

require_once './Connect.php';
$database = ['dsn' => 'mysql:host=localhost;dbname=ecole_multimedia', 'password' => 'root', 'username' => 'antoine'];
$connect = new Connect($database);
$pdo = $connect->getDB();
/* ------------------------------------------------- *\
    That's all
\* ------------------------------------------------- */
$sql = "SELECT * FROM posts";
$stmt = $pdo->query($sql);
foreach ($stmt as $post) {
    echo "<h1>{$post->title}</h1>";
    echo "<p>Statut de l'article: {$post->status}</p>";
}
Example #3
0
<?php

require_once __DIR__ . '/Model.php';
require_once __DIR__ . '/Connect.php';
require_once __DIR__ . '/Post.php';
require_once __DIR__ . '/User.php';
$database = ['dsn' => 'mysql:host=localhost;dbname=ecole_multimedia', 'password' => 'root', 'username' => 'antoine'];
$connect = new Connect($database);
/* ------------------------------------------------- *\
    Name of Model $postModel or $userModel ...
\* ------------------------------------------------- */
$postModel = new Post($connect->getDB());
var_dump($postModel->count());
$posts = $postModel->select(['title', 'status', 'content'])->where('id', '>', 1)->where('status', '=', 'published')->get();
foreach ($posts as $post) {
    echo "<h1>{$post->title}</h1>";
}
/* ------------------------------------------------- *\
    Count method
\* ------------------------------------------------- */
var_dump($postModel->count());
var_dump($postModel->where('id', '>', 1)->count());
/* ------------------------------------------------- *\
    Method all
\* ------------------------------------------------- */
var_dump($postModel->all());
$posts = $postModel->all();
foreach ($posts as $post) {
    echo "<h1>{$post->title}...</h1>";
}
/* ------------------------------------------------- *\
Example #4
0
<?php

require_once __DIR__ . '/Model.php';
require_once __DIR__ . '/Connect.php';
$database = ['host' => 'localhost', 'dbname' => 'ecole_multimedia', 'password' => 'root', 'username' => 'antoine'];
$connect = new Connect($database);
$model = new Model($connect->getDB());
$model->table = 'posts';
$posts = $model->select(['title', 'status', 'content'])->where('id', '>', 1)->where('status', '=', 'published')->get();
foreach ($posts as $post) {
    echo "<h1>{$post->title}</h1>";
}
var_dump($model->count());
var_dump($model->where('id', '>', 1)->count());
Example #5
0
$cart = new Cart(new SessionStorage('biocoop'));
$cart->buy($apple, 10);
$cart->buy($raspberry, 10);
$cart->buy($strawberry, 10);
var_dump($cart->total());
$cart->restore($apple);
var_dump($cart->total());
$cart->reset();
var_dump($cart->total());
/* ------------------------------------------------- *\
    DBStorage
\* ------------------------------------------------- */
unset($cart);
exec('sh ./install.sh');
$conn = new Connect(['host' => 'localhost', 'dbname' => 'db_biocoop', 'username' => 'tony', 'password' => 'tony']);
$dbStorage = new DBStorage('products', $conn->getDB());
$cart = new Cart($dbStorage);
$cart->buy($apple, 10);
$cart->buy($raspberry, 10);
$cart->buy($strawberry, 10);
var_dump($cart->total());
//$cart->restore($apple);
var_dump($cart->total());
//$cart->reset();
var_dump($cart->total());
// cart uri
//$productsCart = $cart->getCart();
//
//foreach($productsCart as $p)
//{
//    $product = new Product($p->name, $p->price);