Home  >  Article  >  php教程  >  insert into 封装

insert into 封装

PHP中文网
PHP中文网Original
2016-05-25 16:58:351183browse

php代码

//添加数据

function inserttable($tablename, $insertsqlarr, $returnid=0) 
{	
	$insertkeysql = $insertvaluesql = $comma = '';
	foreach ($insertsqlarr as $insert_key => $insert_value) {
		$insertkeysql .= $comma.'`'.$insert_key.'`';
		$insertvaluesql .= $comma.'\''.$insert_value.'\'';
		$comma = ', ';
	}

	mysql_query("insert into $tablename($insertkeysql)VALUES($insertvaluesql)");
	if($returnid) {
		return mysql_insert_id();
	}
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn