美文网首页
twt学习第三次作业

twt学习第三次作业

作者: Hie_9e55 | 来源:发表于2017-10-21 09:43 被阅读0次

    这次作业比较迷,还在懵逼中
    目前只改写了PDOModle.class.php文件,其他几个文件之间的逻辑关系还没搞清楚emmmmm

    <?php//这里是PDOModle.class.php,大体是根据社长给的Modle.class.php改写的
    
    namespace MyProject;
    require_once ("iModel.php");
    
    class PDOModel implements iModel
    {
        protected $connection;//储存一个POD对象
    
        protected $sql;//储存sql语句
    
        protected $exec_line;//储存exec函数执行所改变的行数
    
        // your code
    
        public function __construct($dbDsn, $dbUsername, $dbPassWord)
        {
            $this->connection = new \PDO($dbDsn, $dbUsername, $dbPassWord);
        }
    
        public function hasError()
        {
            return $this->connection->errorCode() ? true : false;
        }
    
        public function getError()
        {
            return $this->connection->errorCode();
        }
    
        public function sql()
        {
            return $this->connection->exec($this->sql);
        }
    
        public function update(string $statement)
        {
            $this->sql = $statement;
            $this->exec_line = $this->sql();
            if ($this->hasError()) {
                return null;
            }
            echo "update" . $this->exec_line . "rows\n";
        }
    
        public function insert(string $statement)
        {
            $this->sql = $statement;
            $this->exec_line = $this->sql();
            if ($this->hasError()) {
                return null;
            }
            echo "insert" . $this->exec_line . "rows\n";
        }
    
        public function delete(string $statement)
        {
            $this->sql = $statement;
            $this->exec_line = $this->sql();
            if ($this->hasError()) {
                return null;
            }
            echo "delete" . $this->exec_line . "rows\n";
        }
    
        public function select(string $statement)
        {
            $this->sql = $statement;
            $result = $this->connection->query($this->sql);
            if ($this->hasError()) {
                return null;
            }
            echo $result->fetch(\PDO::FETCH_ASSOC);
        }
    
        public function __destruct()
        {
            // TODO: Implement __destruct() method.
            if ($this->connection)
                $this->connection = NULL;
        }
    
    }
    

    目前还未测试emmmm

    相关文章

      网友评论

          本文标题:twt学习第三次作业

          本文链接:https://www.haomeiwen.com/subject/ybtiuxtx.html