Blogger Information
Blog 34
fans 0
comment 0
visits 20523
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 命名空间的使用
小庄
Original
623 people have browsed it

php 命名空间的使用

admin\constroller目录,一般建议目录与命名空间对应

  1. <?php
  2. namespace admin\constroller;
  3. class Login{
  4. }
  5. `

自动加载类文件,通过spl_autoload_register方法实现,该类文件与admin目录同级

  1. <?php
  2. spl_autoload_register(function($className) {
  3. echo '没有拼接的namespace:'.$className."<br/>";
  4. // $file = __DIR__.'\\controller\\'.str_replace('\\',DIRECTORY_SEPARATOR,$className).'.php';
  5. $file = str_replace('\\',DIRECTORY_SEPARATOR,$className).'.php';
  6. echo '拼接后的namespace:'.$file;
  7. if(!(is_file($file) && file_exists($file))){
  8. throw new \Exception("类 - 文件名不合法或文件不存在");
  9. }
  10. require $file;
  11. });

通过require 将自动加载类文件引入,其次使用use关键字引入命名空间

  1. <?php
  2. require 'admin\autoload.php';
  3. use admin\constroller\Login; //引入Login类所在的命名空间
  4. $a = new Login();

MySql常用ddl dml
DML:
select from tablename;
select
from tablename where id = 123;
select * from tablename where id = 123 and name = ‘zhangsan’;
update tablename set name=’wangwu’ where id = 123;
delete from tablename where id = 123 and name = ‘wangwu’;
insert into tablename(id,name,…) values(123,’lisi’,…)
update,delete 一定主义带上where条件,否则搞不好就删库跑路了,切记切记。

DDL:
create database test;
create database test character set utf-8;   # 设置编码
show database;
use test 使用数据库
select database(); 查看当前使用的数据库
drop database test; 删除数据库

Correcting teacher:PHPzPHPz

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!