Correction status:qualified
Teacher's comments:
类就好比盖房子的图纸,对象就是按照图纸建好的房子,盖房子的时候调用图纸去盖,现有图纸才有的房子。
<?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');//设置端默认的字符编码集
点击 "运行实例" 按钮查看在线实例