当前位置: 首页>>代码示例>>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;未经允许,请勿转载。