贡献一个自己写的PHP函数库,小项目用得着
时间:2010-09-27
来源:互联网
<?php
/*
作者:遥远的期待
QQ:15624575
主页:www.phptogether.com
*/
/*
如果查询到数据,该函数返回一个二维数组;否则,返回false
*/
function Query($sql){
$res = mysql_query($sql);
if(mysql_num_rows($res)){
while ($arr=mysql_fetch_array($res)){
$result[]=$arr;
}
}else{
$result = false;
}
return $result;
}
/*
删除一行,参数1:表名;参数2:列名;参数3:该列的值
*/
function DeleteRow($table,$col,$value){
$str="DELETE FROM `$table` WHERE `$table`.`$col` = \"$value\" LIMIT 1";
mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
删除所有满足条件的行,参数1:表名;参数2:列名;参数3:该列的值
*/
function DeleteAll($table,$col,$value){
$str="DELETE FROM `$table` WHERE `$table`.`$col` = \"$value\"";
mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
按指定要求查询一行,该函数的where子句只能包含一个条件,如果有记录返回结果数组,否则返回false
*/
function SelectRow($table,$col,$value){
$str = "SELECT * FROM `$table` WHERE `$col` =$value LIMIT 0 , 1";
$res = mysql_query($str);
if(mysql_num_rows($res)){
$result=mysql_fetch_array($res);
return $result;
}else{
return false;
}
}
/*
按指定要求更新一行,参数1:表名;参数2:列名;参数3:该列的值;参数4:id
*/
function UpdateRow($table,$col,$value,$id){
$str = "UPDATE `$table` SET `$col` = '$value' WHERE `$table`.`id` =$id LIMIT 1 ;";
$res = mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
按指定要求对字段进行数学加操作
*/
function UpdateAdd($table,$col,$value,$id){
$str = "UPDATE `$table` SET `$col` = $col+$value WHERE `$table`.`id` =$id LIMIT 1 ;";
$res = mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
按指定要求对字段进行数学减操作
*/
function UpdateSub($table,$col,$value,$id){
$str = "UPDATE `$table` SET `$col` = $col-$value WHERE `$table`.`id` =$id LIMIT 1 ;";
$res = mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
删除数组中指定键的元素,不打乱数组顺序
*/
function array_del_key($array,$del){
foreach ($array as $key=>$value){
if("$key"!="$del"){
$b[$key] = $value;
}
}
return $b;
}
/*
上传文件并压缩
*/
function upload($photo){
$uploaddir = '../upload/';
$piece = explode('.',$photo['name']);
$uploadfile = $uploaddir . md5($piece[0]).'.'.$piece[1];
$result = move_uploaded_file($photo['tmp_name'], $uploadfile);
if(!$result){
return false;
}
list($width_orig, $height_orig) = getimagesize($uploadfile);
if ($width_orig!=61||$height_orig!=61) {
$image_p = imagecreatetruecolor(61, 61);
if($piece[1]=="jpg"||$piece[1]=="jpeg"){
$image = imagecreatefromjpeg($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagejpeg($image_p,$uploadfile);
}else if($piece[1]=="gif"){
$image = imagecreatefromgif($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagegif($image_p,$uploadfile);
}
}
return basename($uploadfile);
}
?>
/*
作者:遥远的期待
QQ:15624575
主页:www.phptogether.com
*/
/*
如果查询到数据,该函数返回一个二维数组;否则,返回false
*/
function Query($sql){
$res = mysql_query($sql);
if(mysql_num_rows($res)){
while ($arr=mysql_fetch_array($res)){
$result[]=$arr;
}
}else{
$result = false;
}
return $result;
}
/*
删除一行,参数1:表名;参数2:列名;参数3:该列的值
*/
function DeleteRow($table,$col,$value){
$str="DELETE FROM `$table` WHERE `$table`.`$col` = \"$value\" LIMIT 1";
mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
删除所有满足条件的行,参数1:表名;参数2:列名;参数3:该列的值
*/
function DeleteAll($table,$col,$value){
$str="DELETE FROM `$table` WHERE `$table`.`$col` = \"$value\"";
mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
按指定要求查询一行,该函数的where子句只能包含一个条件,如果有记录返回结果数组,否则返回false
*/
function SelectRow($table,$col,$value){
$str = "SELECT * FROM `$table` WHERE `$col` =$value LIMIT 0 , 1";
$res = mysql_query($str);
if(mysql_num_rows($res)){
$result=mysql_fetch_array($res);
return $result;
}else{
return false;
}
}
/*
按指定要求更新一行,参数1:表名;参数2:列名;参数3:该列的值;参数4:id
*/
function UpdateRow($table,$col,$value,$id){
$str = "UPDATE `$table` SET `$col` = '$value' WHERE `$table`.`id` =$id LIMIT 1 ;";
$res = mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
按指定要求对字段进行数学加操作
*/
function UpdateAdd($table,$col,$value,$id){
$str = "UPDATE `$table` SET `$col` = $col+$value WHERE `$table`.`id` =$id LIMIT 1 ;";
$res = mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
按指定要求对字段进行数学减操作
*/
function UpdateSub($table,$col,$value,$id){
$str = "UPDATE `$table` SET `$col` = $col-$value WHERE `$table`.`id` =$id LIMIT 1 ;";
$res = mysql_query($str);
if(mysql_affected_rows()!="-1"){
return true;
}else{
return false;
}
}
/*
删除数组中指定键的元素,不打乱数组顺序
*/
function array_del_key($array,$del){
foreach ($array as $key=>$value){
if("$key"!="$del"){
$b[$key] = $value;
}
}
return $b;
}
/*
上传文件并压缩
*/
function upload($photo){
$uploaddir = '../upload/';
$piece = explode('.',$photo['name']);
$uploadfile = $uploaddir . md5($piece[0]).'.'.$piece[1];
$result = move_uploaded_file($photo['tmp_name'], $uploadfile);
if(!$result){
return false;
}
list($width_orig, $height_orig) = getimagesize($uploadfile);
if ($width_orig!=61||$height_orig!=61) {
$image_p = imagecreatetruecolor(61, 61);
if($piece[1]=="jpg"||$piece[1]=="jpeg"){
$image = imagecreatefromjpeg($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagejpeg($image_p,$uploadfile);
}else if($piece[1]=="gif"){
$image = imagecreatefromgif($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagegif($image_p,$uploadfile);
}
}
return basename($uploadfile);
}
?>
作者: 遥远的期待 发布时间: 2010-09-27
来帮你顶下
作者: ziziartemis 发布时间: 2010-09-27
好东西啊.www.ju-qi.com
作者: juqi 发布时间: 2010-09-27
帮你顶上去!
作者: wuchunuan 发布时间: 2010-09-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28