php对mysql 插入语句的简单封装
通俗的写法是这样的:
INSERT INTO `goods` (`name`,'age')VALUES('李小龙','32'); 简单封装:
function insert($table,$file)
{
foreach($file as $key =>$val){
$_val = is_array($val) ? $val : mysql_real_escape_string($val);
$fileds[] = "`".$key."`";
$values[] = "'".$_val."'";
}
return mysql_query("INSERT INTO `$table` (". implode(",",$fileds).") VALUES (". implode(",",$values).")");
}
//调用
$file = array(
'name'=>'李小龙',
'age'=>'男'
)
insert('goods',$file);