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