• 复习笔记


    <?php
    $dh=opendir("./");
    var_dump($dh);
    $list=array();
    while(($item=readdir($dh))!==false){
        $list[]=$item;
    
    }
    foreach ($list as $key => $value) {
        echo $value,'<br/>';
    }
    var_dump(readdir($dh));
    
    $age=12;
    class Human{
        public $name;
        public $age=19;
        public function __construct($name){
            $this->name=$name;
        }
        public static function eat(){
            echo '吃饭','<br/>';
        }
        public static function ha(){
            eat();
        }
        public function __destruct(){
            echo '对象销毁时自动调用';
        }
    }
    function eat(){
        echo "还吃",'<br/>';
    }
    eat();
    Human::eat();
    Human::ha();
    
    $lisi=new Human('lisi');
    
    //封装MySQL类
    class MysqlFun{
        private $host;
        private $user;
        private $password;
        private $conn;
        public function __construct($host,$user,$password){
            $this->host=$host;
            $this->user=$user;
            $this->password=$password;
            $this->conn=mysql_connect('localhost','root','111111');
        }
        public function getConn(){
            // $conn=mysql_connect($this->host,$this->user,$this->password);
            return $this->conn;
        }
        //向数据库发送数据
        public function query($sql){
            return mysql_query($sql,$this->conn);
        }
        //查询多行数据,返回二维数组,一行数据一个一维数组
        public function getAll($sql){
            $rs=mysql_query($sql,$this->conn);
            $arr=array();
            while(($row=mysql_fetch_assoc($rs))!==false){
                $arr[]=$row;
            }
            return $arr;
        } 
        //查询一行数据,返回一维数组
        public function getRow($sql){
            $rs=mysql_query($sql,$this->conn);
            return mysql_fetch_assoc($rs);
        }
        //查询一行一列数据,返回那个值
        public function getOne($sql){
            $rs=mysql_query($sql.$this->conn);
            $arr=mysql_fetch_row($rs);
            return $arr[0];
        }
        public function close(){
            mysql_close($this->conn);
        }
    }
    
    $wode=new MysqlFun('localhost','root','111111');
    $wode->query('set names utf8');
    $wode->query('use test1');
    $sql='select * from stu';
    $array=$wode->getAll($sql);
    print_r($array);
    
    //继承extends
    /*父类私有的属性,可以理解为不能继承,因为继承了但不能访问
    protected修饰的属性,继承之后再子类内部能访问,但在类外部不能访问
    */
    class animal{
        public function eat(){
            echo 'animal会吃';
        }
        protected function getmoney(){
            echo '我有好多钱';
        }
    }
    class people extends animal{
        public function __construct(){
            parent::eat();
        }
        public static function run(){
            echo '跑啊跑';
        }
    }
    $zhangsan=new people();
    $zhangsan->run();
    //静态方法也可以用对象名调用
    class hum extends people{
        public function __construct(){
            $this->getmoney();
        }
    }
    $hu=new hum();
    echo '<br/>';
    
    ?>
    

    有些数据没有经过严格的验证,然后直接拼接 SQL 去查询。导致漏洞产生,比如:

    $id  = $_GET['id'];
    $sql = "SELECT name FROM users WHERE id = $id";
    

     因为没有对 $_GET['id'] 做数据类型验证,注入者可提交任何类型的数据,比如 " and 1= 1 or " 等不安全的数据。如果按照下面方式写,就安全一些。

    $id  = intval($_GET['id']);
    $sql = "SELECT name FROM users WHERE id = $id";
    

     复习笔记:

  • 相关阅读:
    第23条:通过委托与数据源协议进行对象间通信
    第22条:理解NSCopying协议
    第21条:理解Objective-C错误模型
    第20条:为私有方法名加前缀
    《隐藏键盘》《隐藏PickerView控键》如果是xib中 点击空白处隐藏键盘
    《弹出提示》UIAlertView 弹出提示
    MAC 问题。
    小技巧
    控制器的生命周期
    问题。控制器跳转
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4755742.html
Copyright © 2020-2023  润新知