// 弹框跳转
function alert($msg,$url=''){
echo "<script>";
echo "alert('$msg');";
if($url){
echo "window.location.href='$url';";
}else{
echo "window.history.go(-1);";
}
echo "</script>";
}
//获取单条数据
function getONE($sql){
$sql = mysql_query($sql);
$list = array();
if($sql && mysql_affected_rows()>0){
$list = mysql_fetch_assoc($sql);
}return $list;
}
//获取多条数据
function getALL($sql){
$sql = mysql_query($sql);
$list = array();
if($sql && mysql_affected_rows()>0){
while($row = mysql_fetch_assoc($sql)){
$list[] = $row;
}
}return $list;
}
/**
* [delete 删除数据]
* @param [string] $table [表名]
* @param [string] $where [条件]
* @return [boolean] [返回结果]
*/
//删除数据SQL语句封装
function delete($table,$where){
//构造删除的SQL语句
$sql = "DELETE FROM `$table` WHERE $where;";
//把SQL语句执行
$res = mysql_query($sql);
//判断是否执行成功
if($res && mysql_affected_rows()>0){
return true;
}else{
return false;
}
}
/**
* [update 更新数据]
* @param [string] $table [表名]
* @param [array] $array [要更新的数据]
* @param [string] $where [条件]
* @return [type] [返回结果]
*/
//更新数据SQL语句封装
function update($table,$array,$where){
$str = '';
foreach($array as $key => $value){
$str .= "`".$key."`='".$value."',";
}
//去除最右边的逗号
$str = rtrim($str,',');
//构造更新的SQL语句
$sql = "UPDATE `$table` SET $str WHERE $where";
// dump($sql);exit;
$res = mysql_query($sql);
//判断是否执行成功
if($res){
return true;
}else{
return false;
}
}
/**
* [insert 插入数据]
* @param [string] $table [表名]
* @param [array] $data [数据]
* @return [bool]
php函数封装
最新推荐文章于 2021-04-29 20:07:20 发布