Blogger Information
Blog 30
fans 0
comment 0
visits 20080
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
10月10日作业,写一个分级命名空间以及实现一个Trait类
人生就像过山车的博客
Original
446 people have browsed it

老师好, 10月10日作业如下,写一个分级明明空间以及Trait类的实现,如果出现页面错误,不是因为远程服务器数据库里,没有相应的表引起的,而是因为数据库密码不同引起的。点击页面底部的php中文网图片可以返回我的博客页面,老师辛苦了,感恩感恩。 最近事很多,比较忙,而且由于纽约进入了冬令时,从而时差变为了13小时,以至于无法第一时间看直播了,但是还是会忙里偷闲看录播以及补写作业的,多谢多谢,代码如下:

namespace _1010\one;
              class Demo1{
                static function demo1(){
                  echo __CLASS__;
                  echo '<br>';                }
              }
              
              Demo1::demo1();
              
              namespace _1010\two;
              
              class Demo2{
                static function demo2(){
                     echo __CLASS__;
                     echo '<br>';                }            
                       }       
                                           
                Demo2::demo2();
             
              spl_autoload_register(function($classname){
                $path = str_replace('\\',DIRECTORY_SEPARATOR,$classname); 
                 $path = __DIR__.'/'.'.php';                
                 if(file_exists($path))include $path;             
                 });
            use PDO;

            trait DBO{
                 function conn($dsn,$username,$password){
                      return new PDO($dsn,$username,$password);                 } 
                                 }
            trait Query{
                function select($pdo){
                    $stmt = $pdo->prepare('SELECT * FROM ps4');
                    $stmt->execute();
                    return $stmt->fetchAll(PDO::FETCH_ASSOC);                 }           
                     }
            class Get{
                  use DBO;
                  use Query;
                  public $pdo = null;
                 
                 function __construct($dsn,$username,$password)   {  
                 $this->pdo = $this->conn($dsn,$username,$password);  }
                 
                 function get(){
                     return $this->select($this->pdo);                 }           
                      }
           
            $dsn = 'mysql:host=127.0.0.1;dbname=gamepop';
           
            $username = 'root';
           
            $password = '';
           
            $get = new Get($dsn,$username,$password);
           
            print_r($get->get());


10月10日作业,点击查看

以上作业链接所在的服务器如在国内不能查看,参见以下效果图

屏幕快照 2020-01-09 下午3.54.48.png

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments