蝙蝠岛资源网 Design By www.hbtsch.com
本文实例讲述了PHP常用的类封装。分享给大家供大家参考,具体如下:
这4个类分别是Mysql类、 分页类、缩略图类、上传类。
Mysql类
<"set names ".$cfg['charset']);//设置字符集
}
return self::$link;
}
/**
* 执行一条sql语句
* @param str $sql 查询语句
* @return obj 结果集对象
*/
public static function query($sql){
return self::conn()->query($sql);
}
/**
* 获取多行数据
* @param str $sql 查询语句
* @return arr 多行数据
*/
public static function getAll($sql){
$data = array();
$res = self::query($sql);
while($row = $res->fetch_assoc()){
$data[] = $row;
}
return $data;
}
/**
* 获取一行数据
* @param str $row 查询语句
* @return arr 单行数据
*/
public static function getRow($row){
$res = self::query($sql);
return $res->fetch_assoc();
}
/**
* 获取单个结果
* @param str $sql 查询语句
* @return str 单个结果
*/
public static function getOne($sql){
$res = self::query($sql);
$data = $res->fetch_row();
return $data[0];
}
/**
* 插入/更新数据
* @param str $table 表名
* @param arr $data 插入/更新的数据
* @param str $act insert/update
* @param str $where 更新条件
* @return bool 插入/更新是否成功
*/
public static function exec($table,$data,$act='insert',$where='0'){
//插入操作
if($act == 'insert'){
$sql = 'insert into '.$table;
$sql .= ' ('.implode(',',array_keys($data)).')';
$sql .= " values ('".implode("','",array_values($data))."')";
}else if($act == 'update'){
$sql = 'update '.$table.' set ';
foreach ($data as $k => $v) {
$sql .= $k.'='."'$v',";
}
$sql = rtrim($sql,',');
$sql .= ' where 1 and '.$where;
}
return self::query($sql);
}
/**
* 获取最近一次插入的主键值
* @return int 主键
*/
public static function getLastId(){
return self::conn()->insert_id;
}
/**
* 获取最近一次操作影响的行数
* @return int 影响的行数
*/
public static function getAffectedRows(){
return self::conn()->affected_rows;
}
/**
* 关闭数据库连接
* @return bool 是否关闭
*/
public static function close(){
return self::conn()->close();
}
}
"htmlcode">
<"htmlcode">
<"image".$this->getType();
$method($image,$this->thumbPath);
}
/**
* 进行绘画操作
* @return [type] [description]
*/
public function draw(){
if(!($type = $this->getType())){
echo "文件类型不支持";
return ;
}
//创建大图和小图的画布
$method = "imagecreatefrom".$type;
$bigCanvas = $method($this->sourcePath);
$smallCanvas = imagecreatetruecolor($this->thumbWidth, $this->thumbHeight);
//创建白色画笔,并给小图画布填充背景
$white = imagecolorallocate($smallCanvas, 255, 255, 255);
imagefill($smallCanvas, 0, 0, $white);
//计算大图的缩放比例
$rate = $this->calculateRate();
//计算大图缩放后的大小信息
$info = $this->getImageSizeByRate($rate);
//进行缩放
imagecopyresampled($smallCanvas, $bigCanvas,
($this->thumbWidth - $info['w']) / 2 , ($this->thumbHeight - $info['h']) / 2,
0, 0, $info['w'], $info['h'], $this->sourceWidth, $this->sourceHeight);
//保存成文件
$this->saveFile($smallCanvas);
//销毁画布
imagedestroy($bigCanvas);
imagedestroy($smallCanvas);
}
}
"htmlcode">
<meta charset="utf8"/>
<"没有上传文件";
return;
}
$info = $this->getInfo($flag);
if(!$this->checkExt($info['name'])){
echo "不支持的文件类型";
return;
}
if(!$this->checkSize($info['size'])){
echo "文件大小超过限制";
return;
}
$filename = $this->randName().'.'.$this->getExt($info['name']);
$dir = $this->createDir();
if(!move_uploaded_file($info['tmp_name'], $dir.'/'.$filename)){
echo "文件上传失败";
}else{
return array('filename'=>$filename,'dir'=>$dir);
}
}
}
"_blank" href="//www.jb51.net/Special/84.htm">php+mysql数据库操作入门教程》、《php+mysqli数据库程序设计技巧总结》、《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP网络编程技巧总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
标签:
PHP,封装,工具类
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无PHP常用的类封装小结【4个工具类】的评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2025年10月30日
2025年10月30日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]