Correction status:qualified
Teacher's comments:
1.类:是一个抽象的东西,比如人类,动物类,鸟类,他可以有多种属性,比如人,有年龄,身高,体重;
对象:我们可以把任何一个东西称作为对象,每个对象都有它自己独特的属性
2.参考object/demo3.php,自定义类与实例化,要求必须将属性私有化,通过公共接口__set()和get()进行访问:
<?php //require 'human.php'; $human = new human('jack',18,128); echo $human->name,'<br>'; class human //人类 { private $name; private $age; private $weight; public function __construct($name,$age,$weight)//实例化 { $this->name = $name; $this->age = $age; $this->weight = $weight; } public function __get($name){ $msg = null; if (isset($this->$name)) { $msg = $this->$name; } else{ $msg = "无此属性"; } return $msg; } public function __set($name,$value){ $this->$name = $value; } }
点击 "运行实例" 按钮查看在线实例
3. 编程: MySQL常用的增删改查语句(CURD):
<?php //查询: // SELECT * FROM user WHERE id = 0; //增加: // INSERT 'table' ('item1','item2') VALUES ('value1','value2'); //更新: // UPDATE 'table' SET ('item1'='value1') WHERE id = 0; //删除: // DELETE FROM 'table' WHERE id = 0;
点击 "运行实例" 按钮查看在线实例
4.编程: 数据库的连接与检测,将连接参数写到独立的配置文件,要求配置参数必须用数组来实现,并在连接脚本中正确引用。:
<?php //引用指定文件 require 'config.php'; //设置错误级别 error_reporting(E_ALL ^E_WARNING); //连接指定数据库 $mysqli = new mysqli($db['host'],$db['user'],$db['pwd'],$db['name']); //如果连接错误 if ($mysqli->connect_errno) { // 自定义错误提示信息 die('连接错误'.$mysqli->connect_errno.': '. $mysqli->connect_error); } //设置数据库编码类型 $mysqli->set_charset($db['charset']); //config.php 文件内容: $db_host = '127.0.0.1'; $db_user = 'root'; $db_pwd = 'root'; $db_name = 'php'; $db_charset = 'utf8'; $db = [ 'host' => '127.0.0.1', 'user' => 'root', 'pwd' => 'root', 'name' => 'php', 'charset' => 'utf8' ];
点击 "运行实例" 按钮查看在线实例
6. 手写: 与MySQLil连接相关的几个属性和方法的名称,参数,与功能和用法: