本文整理匯總了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);