批改状态:合格
老师批语:
1问答: 什么类,什么是对象,举例说明
类就是对象的模板,对象是类的实例,例如女明星就是一个类,凤姐,冰冰姐这些就是对象。
2代码:
<?php
class Person{
private $name;//私有属性姓名
private $age;//私有属性年龄
private $sex;//私有属性姓别
public function __construct($name,$age,$sex)//构造方法
{
$this->name=$name;
$this->age=$age;
$this->sex=$sex;
}
private $data=[];//属性收集器
//创建对外访问的公共接口
// 类中用双下划线的方法是系统定义,由系统自动调用,叫魔术方法
public function __get($name){
$msg=null;
if(isset($this->$name)){
$msg=$this->$name;
}elseif(isset($this->data[$name])){
$msg=$this->data[$name];
}else{
$msg='无此属性';
}
return $msg;
}
//设置器
public function __set($name,$value){
return $this->$name=$value;
}
}点击 "运行实例" 按钮查看在线实例
<?php
require './demo1.php';
$p=new Person('tom',18,'man');
echo $p->name;
$p->age=20;
echo $p->age;
echo $p->vv;点击 "运行实例" 按钮查看在线实例
SELECT * FROM `staff` //查询
SELECT `name`,`age` FROM `staff`
SELECT 30+50 as Result
SELECT * FROM `staff`
SELECT `name`,`age` FROM `staff`
SELECT 30+50 as Result
SELECT * FROM `staff`
SELECT `name`,`age` FROM `staff`
SELECT 30+50 as Result
SELECT * FROM `staff`
SELECT `name`,`age` FROM `staff`
SELECT 30+50 as Result
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
INSERT INTO `staff`( `name`,`age` ) VALUES('tom',20);//增加
delete from `staff` where `staff_id`=12; //删除
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
delete from `staff` where `staff_id`=12;
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改
update `staff` set `name`='lilei' where `staff_id`=17; //修改点击 "运行实例" 按钮查看在线实例
<?php $db=[ 'host'=>'127.0.0.1', //主机名 'user'=>'root', //用户名 'pwd'=>'root', //密码 'name'=>'php', //数据库 'charset'=>'utf8' //字符集 ];
点击 "运行实例" 按钮查看在线实例
<?php
require 'config.php';
error_reporting(E_ALL ^E_WARNING);
$mysqli=new mysqli($db['host'],$db['user'],$db['pwd'],$db['name']);
//var_dump($myqli);
//判断是否连接成功?
if($mysqli->connect_errno){
// 自定义错误提示信息
die('错误信息:'.$mysqli->connect_errno.':'.$mysqli->connect_error);
}
echo '<h1>连接成功</h1>';
//设置kehu端默认的字符编码集
$mysqli->set_charset($db['charset']);点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号