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


PHP DataBase::getPdo方法代碼示例

本文整理匯總了PHP中DataBase::getPdo方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataBase::getPdo方法的具體用法?PHP DataBase::getPdo怎麽用?PHP DataBase::getPdo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataBase的用法示例。


在下文中一共展示了DataBase::getPdo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: undoEstimation

 public function undoEstimation($tableName, $columnName, $resourceId)
 {
     $db = DataBase::getPdo();
     $q = "DELETE FROM {$tableName}  WHERE {$columnName} = ?;";
     $stm = $db->prepare($q);
     $stm->bindValue(1, $resourceId);
     $res = $stm->execute();
     if ($res) {
         if ($stm->rowCount() == 1) {
             return $this->makeResponse(true);
         } else {
             return $this->makeResponse(false, 'action is already done');
         }
     } else {
         return $this->makeResponse(false, 'unknown error');
     }
 }
開發者ID:asgardxf,項目名稱:phpblog,代碼行數:17,代碼來源:EstimatableResource.class.php

示例2: getData

    public function getData($day)
    {
        $db = DataBase::getPdo();
        $getAvalableDays = "SELECT DISTINCT publishing_date FROM posts;";
        $stm = $db->query($getAvalableDays);
        $available = [];
        # array_map(function($e){return $e["publishing_date"];},  $stm->fetchAll());
        while ($row = $stm->fetch()) {
            array_push($available, $row["publishing_date"]);
        }
        if (!in_array($day, $available)) {
            return ['result' => 'error', 'message' => 'cannot find specified date', 'available' => $available];
        }
        #$q = "SELECT id, likes, dislikes FROM posts WHERE publishing_date = '2015-10-12';";
        $q = "SELECT id, likes, dislikes FROM posts WHERE publishing_date = ?;";
        $stm = $db->prepare($q);
        $stm->bindValue(1, $day);
        $stm->execute();
        $posts = $stm->fetchAll();
        $commentsWithAuthorsToPosts = [];
        $q = <<<EOD
\t\t\tSELECT  COUNT(id) as comments_count,
\t\t\tCOUNT( DISTINCT author) as unique_author
\t\t\tFROM comments WHERE post_id = ?;
EOD;
        foreach ($posts as &$row) {
            #$comments = $db->query(
            $stm = $db->prepare($q);
            $stm->bindValue(1, $row["id"]);
            $stm->execute();
            #$commentsWithAuthorsToPosts[$row["id"]] = $stm->fetch();
            $c = $stm->fetch();
            $row["unique_authors"] = $c["unique_author"];
            $row["comments_count"] = $c["comments_count"];
        }
        return ['postsStat' => $posts, 'available' => $available];
    }
開發者ID:asgardxf,項目名稱:phpblog,代碼行數:37,代碼來源:StatsProvider.class.php

示例3: getList

 public static function getList($postId)
 {
     $db = DataBase::getPdo();
     $q = 'SELECT content, author, id, publishing_date, publishing_time, likes, dislikes FROM comments WHERE post_id = ?;';
     $stm = $db->prepare($q);
     $stm->bindValue(1, $postId);
     $stm->execute();
     return $stm->fetchAll();
 }
開發者ID:asgardxf,項目名稱:phpblog,代碼行數:9,代碼來源:Comment.class.php

示例4: get

    public static function get($id)
    {
        $db = DataBase::getPdo();
        $q = <<<EOD
\t\tSELECT content, title, author,
\t\tpublishing_date, publishing_time,
\t\tjson_attrs,
\t\tlikes, dislikes,
\t\tfavorites, id
\t\tFROM posts WHERE id = :id;
EOD;
        $stm = $db->prepare($q);
        $stm->execute(['id' => $id]);
        $result = $stm->fetch();
        if ($result) {
            $result['karma'] = static::s_karma($id);
            return $result;
        }
        return $stm->fetch();
    }
開發者ID:asgardxf,項目名稱:phpblog,代碼行數:20,代碼來源:Post.class.php


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