本文整理汇总了PHP中Connect::getDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Connect::getDB方法的具体用法?PHP Connect::getDB怎么用?PHP Connect::getDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connect
的用法示例。
在下文中一共展示了Connect::getDB方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
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...');
}
}
示例2: Connect
<?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>";
}
示例3: Connect
<?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>";
}
/* ------------------------------------------------- *\
示例4: Cart
$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);