MySQL 操作函数封装

 array( '字段名' => 值, ... ))
		$tbl_name = key($sql);
		$f = join(',', array_keys(current($sql)));
		$v = join("','", array_values(current($sql)));
		$sql = "insert into $tbl_name ($f) values ('$v')";
	}
	$rs = mysql_query($sql) or die(mysql_error()); //执行 SQL 指令
	if(preg_match('/^select\s|show\s/i', $sql)) { // 如果是查询
		while($r = mysql_fetch_assoc($rs)) $ret[] = $r; //则取出全部结果到数组
	}else $res = mysql_affected_rows(); //否则取硬性的行数
	return $ret;
}

你可能感兴趣的:(MySQL 操作函数封装)