2021-01-12 PHP面向对象封装Redis、Memcached、Memcache实例 PHP面向对象封装Redis、Memcached、Memcache实例 Cache.class.php<?php class Mysql { public $link; public function __construct() { $this->conn(); } /** * 连接数据库,从配置文件读取配置信息 */ public function conn() { $cfg = require 'config.php'; $this->link = new mysqli($cfg['host'], $cfg['name'], $cfg['password'], $cfg['databaseName'], $cfg['port']); $this->query('set names ' . $cfg['charset']); } /** * 发送query查询 * @param string $sql sql语句 * @return mix... 2021年01月12日 1,434 阅读 0 评论
2021-01-11 memcached 常用命令及使用说明 memcached 常用命令及使用说明 启动Memcached 常用参数-p <num> 设置TCP端口号(默认设置为: 11211) -U <num> UDP监听端口(默认: 11211, 0 时关闭) -l <ip_addr> 绑定地址(默认:所有都允许,无论内外网或者本机更换IP,有安全隐患,若设置为127.0.0.1就只能本机访问) -c <num> max simultaneous connections (default: 1024) -d 以daemon方式运行 -u <username> 绑定使用指定用于运行进程<username> -m <num> 允许最大内存用量,单位M (默认: 64 MB) -P <file> 将PID写入文件<file>,这样可以使得后边进行快速进程终止, 需要与-d 一起使用 更多可以使用 memcached -h 在linux下:./usr/local/bin/memcached -d -u... 2021年01月11日 1,135 阅读 0 评论
2021-01-06 PHP Smarty 模板引擎 PHP Smarty 模板引擎 1.php<?php class Mini { protected $data = array(); //把外界变量放进data数组 public function assign($k, $v) { $this->data[$k] = $v; } public function comp($temp) { $html = file_get_contents($temp); //注意 下行引用自身的data属性 $html = str_replace('{$', "<?php echo \$this->data['", $html); $html = str_replace('}', "'];?>", $html); $compfile = $temp . '.php'; file_put_contents($compfile, $html); ... 2021年01月06日 1,124 阅读 0 评论
2021-01-04 PHP面向对象封装MySQL操作函数、文件上传 PHP面向对象封装MySQL操作函数、文件上传 Mysql.class.php<?php class Mysql { public $link; public function __construct() { $this->conn(); } /** * 连接数据库,从配置文件读取配置信息 */ public function conn() { $cfg = require 'config.php'; $this->link = new mysqli($cfg['host'], $cfg['name'], $cfg['password'], $cfg['databaseName'], $cfg['port']); $this->query('set names ' . $cfg['charset']); } /** * 发送query查询 * @param string $sql sql语句 * @return m... 2021年01月04日 1,186 阅读 0 评论
2020-12-30 PHP面向对象的自动加载 PHP面向对象的自动加载 实例化某个类时,如MySQL类,需要先require('mysql.php' );如果类比较多,目录也比较多,require文件时,将会变得麻烦我们需要一个自动化的解决方法--自动加载用法:声明一个函数,并注册为"自动加载函数"当系统发现某个类不存在时,会调用此函数,我们可以在函数中加载需要的类文件<?php function myLoad($class){ require $class . '.php'; } //把myLoad注册成自动加载函数 spl_autoload_register('myLoad'); new mysql();//查看效果 2020年12月30日 1,110 阅读 0 评论
2020-12-30 PHP面向对象中的魔术方法 PHP面向对象中的魔术方法 魔术方法:某种场景下,能够自动调用的方法如: __construct、 __destruct、__set、 __get、 __isset、__unset、__call__construct(): 构造方法,new 实例时,自动调用__destruct(): 析构方法,对象销毁时自动调用__get(属性名): 当读取对象的一个不可见属性时,自动调用,并返回值不可见: 未定义或无权访问时__set(属性名,属性值): 当对一个不可见的属性赋值时,自动调用__isset(属性名): 当用isset,或empty判断一个不可见属性时,自动调用__unset(属性名): 当unset一个不可见属性时,自动调用<?php class Human{ //构造方法,new 实例时,自动调用 public function __construct(){ echo '构造方法'; } //析构方法,对象销毁时自动调用 public function __destruct(){ echo '析构方法'; } ... 2020年12月30日 966 阅读 0 评论
2020-12-29 PHP面向对象中的$this、self、parent PHP面向对象中的$this、self、parent <?php // $this 本对象 // self 本类 // parent 父类 class Single { public $rand; public static $ob; //final 方法不能被子类重写,实现单例模式 final protected function __construct() { $this->rand = mt_rand(1000, 9999); } public static function getins() { if (self::$ob == null) { self::$ob = new self(); } return self::$ob; } } var_dump(Single::getins()); class Par { public function __construct() { echo mt_rand(10000, ... 2020年12月29日 924 阅读 0 评论
2020-12-29 PHP面向对象中单例模式 PHP面向对象中单例模式 <?php class Single { public $rand; public static $ob; //final 方法不能被子类重写,实现单例模式 final protected function __construct() { $this->rand = mt_rand(1000, 9999); } public static function getins() { if (Single::$ob == null) { Single::$ob = new Single(); } return Single::$ob; } } var_dump(Single::getins()); var_dump(Single::getins()); 2020年12月29日 807 阅读 0 评论
2020-12-28 PHP中面向对象3种权限详解 PHP中面向对象3种权限详解 public(公有)protected(受保护)private(私有)外部YNN子类中YYN本类中YYY<?php class Human { public $money = '3000'; protected $car = 'BMW'; private $gf = 'mv'; public function par() { echo $this->money; echo $this->car; echo $this->gf; } } class Stu extends Human { public function sub() { echo $this->money; echo $this->car; echo $this->gf; } } $stu = new Stu; $stu->par(); $stu->sub(); //gf没有被继承 echo $s... 2020年12月28日 903 阅读 0 评论
2020-12-23 Layui 多图片上传 Layui 多图片上传 1.html<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>多图片上传</title> <link rel="stylesheet" href="layui/dist/css/layui.css"> <style> .layui-upload-img{width: 92px; height: 92px; margin: 0 10px 10px 0;} </style> </head> <body> <form action="2.php" method="post" enctype="multipart/form-data"> <div class="layu... 2020年12月23日 1,032 阅读 0 评论