批改状态:合格
老师批语:
1.非限定名称:当前空间下使用,类名无空间前缀
2.限定名称:相对路径,类名无全局空间前缀
3.完全限定名称:绝对路径从根空间开始访问\表示根空间
4.通过use关键字来调用命名空间的类,可以通过as关键字简化或起别名避免冲突;如果别名和类名相同时,use语句可以省略as关键字和别名;
5.案例
<?php//命名空间引用方式// 非限定名称namespace one{class Demo{}$str=Demo::class;//非限定名称(当前空间中成员的调用)echo $str."<br>";$str=two\Demo::class;//限定名称(相对当前空间相对路径)echo $str."<br>";}namespace one\two{class Demo{}$str = \one\Demo::class;//完全限定名称(从跟空间开始,调用其他空间的成员)echo $str;}namespace {echo "<hr>";}
1.自动加载函数:spl_autoload_register();
2.自动加载函数的参数:匿名函数(闭包);
3.自适用目录分割符常量:DIRECTORY_SEPARATOR;
4.自动加载器
<?php//自动加载函数spl_autoload_register(function($class){//将类空间名称与类文件所在的路径进行映射,实现自动加载$url=str_replace("\\",DIRECTORY_SEPARATOR,$class);require $url.".php";});
1.数据库
创建create database 数据库名 collate 校验字符集;常见校验字符集:utf8mb4_unicode_ci`
选择默认数据库use 数据库名;
查看所有数据库show databases;或者select
查看建库语句show create database 数据库名;
状态(只能在命令行执行)status
删除drop database 数据库;
2.数据表
create table staffs(sid int unsigned auto_increment not null primary key,name varchar(20) not null comment '姓名',gender enum('male','female') not null comment '性别',email varchar(150) not null comment '邮箱',birthday date not null comment '生日',create_at timestamp not null default current_timestamp comment '创建日期',update_at timestamp not null default current_timestamp on update current_timestamp comment '更新日期') engine = innodb auto_increment = 1 collate = utf8mb4_unicode_ci;
结构desc 表名;
建表语句show create table 表名;
查看数据库中的表show tables;
增加字段alter table staffs add salary int unsigned not null default 2000 after gender;
更新字段alter table staffs change salary salary float unsigned not null default 3000 after gender;
删除字段alter table staffs drop email;
删除表drop table staffs;
清空表数据truncate table staffs;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号