當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Connect::getDB方法代碼示例

本文整理匯總了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...');
     }
 }
開發者ID:Antoine07,項目名稱:Base-Objet,代碼行數:10,代碼來源:Model.php

示例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>";
}
開發者ID:Antoine07,項目名稱:Base-Objet,代碼行數:15,代碼來源:query.php

示例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>";
}
/* ------------------------------------------------- *\
開發者ID:Antoine07,項目名稱:Base-Objet,代碼行數:31,代碼來源:test.php

示例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);
開發者ID:Antoine07,項目名稱:Base-Objet,代碼行數:31,代碼來源:test.php


注:本文中的Connect::getDB方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。