首页 > 数据库技术 > 详细

数据库操作函数(2)

时间:2014-08-26 17:39:17      阅读:382      评论:0      收藏:0      [点我收藏+]
/**
 * 更新数据函数
 * @param 用户提交的表单数据存入数组 $array
 * @param 操作的数据表 $table
 * @param 更新条件 $where
 * @return 影响的数据条数 number
 */
function update($array,$table,$where=NULL){
	foreach($array as $key=>$val){
		$sep=($str==null)?" ":",";
		$str.=$sep.$key."=‘".$val."‘";
	}
	$where=($where==null)?"":"where $where";//增加条件语句
	$query="update {$table} set {$str} $where";
	mysql_query($query);
	return mysql_affected_rows();
}



/**
 * 删除数据函数
 * @param 操作的数据表 $table
 * @param 删除条件 $where
 * @return 影响的条数 number
 */
function delete($table,$where=null){
	$where=($where==null)?"":"where $where";
	$query="delete from {$table} {$where}";
	mysql_query($query);
	return mysql_affected_rows();
}


数据库操作函数(2)

原文:http://itech.blog.51cto.com/192113/1545193

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!