Blogger Information
Blog 18
fans 0
comment 0
visits 9877
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
对象基础与MySQLi对象编程2018年8月29日作业
吕小布的博客
Original
539 people have browsed it

类就好比盖房子的图纸,对象就是按照图纸建好的房子,盖房子的时候调用图纸去盖,现有图纸才有的房子。

实例

<?php
class Person{
    private $name;
    private $sex;
    private $age;
    public function __construct($age,$name,$sex)
    {
        $this->name=$name;
        $this->sex=$sex;
        $this->age=$age;
    }
    public function __get($name)//获取器
    {
        if (isset($this->$name)){
            return $this->$name;
        }else {return '无此属性';}
    }
    public function __set($name, $value)//设置器
    {
        $this->$name=$value;
    }


}

$test=new Person(0,'','');

echo $test->name='小布';
echo $test->age=18;
echo $test->sex='男';

运行实例 »

点击 "运行实例" 按钮查看在线实例

select * from msg//查询数据
select count(*) from msg;
insert into msg (name,age) values ('小布',18);//增
update msg set name='小飞',age=18 where id=3;//改
delete from msg where id=4;//删

数据库的链接与检查

实例

<?php
$db=[
    'host' => '127.0.0.1',
    'user' => 'root',
    'pass' => 'root',
    'name' => 'msg',
    'charset' => 'utf8',
];
$mysqli=new mysqli($db['host'],$db['user'],$db['pass']);
if(mysqli_connect_errno($mysqli)){
    die ('链接Mysql失败'.mysqli_connect_errno($mysqli).':'.mysqli_connect_error($mysqli));
}else{
    echo '链接成功';
}

$mysqli->set_charset(utf8);// 设置默认数据库
$mysqli->select_db('msg');//设置端默认的字符编码集

运行实例 »

点击 "运行实例" 按钮查看在线实例

QQ图片20180904221516.jpg

Correction status:qualified

Teacher's comments:
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
Author's latest blog post