<?php
// 以下变量请根据空间商提供的账号参数修改,如有疑问,请联系服务器提供商

$dbhost = 'localhost';		// 数据库服务器，本地连接用localhost
$dbuser = 'root';			// 数据库用户名
$dbpw = 'yourpassword';		// 数据库密码
$dbname = 'yourdbname';		// 数据库名
$pconnect = 0;				// 数据库持久连接 0=关闭, 1=打开
$dbcharset = 'gbk';			// MySQL 字符集, 可选 'gbk', 'big5', 'utf8', 'latin1'

//=======================================数据库类=========================================
class dbclass {

	var $version = '';
	var $querynum = 0;
	var $link = null;

	function connect($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0, $halt = TRUE, $dbcharset2 = '') {

		$func = empty($pconnect) ? 'mysql_connect' : 'mysql_pconnect';
		if(!$this->link = @$func($dbhost, $dbuser, $dbpw, 1)) {
			$halt && $this->halt('[err]Can not connect to MySQL server[/err]'); //返回失败信息
		} else {
			if($this->version() > '4.1') {
				global $charset, $dbcharset;
				$dbcharset = $dbcharset2 ? $dbcharset2 : $dbcharset;
				$serverset = $dbcharset ? 'character_set_connection='.$dbcharset.', character_set_results='.$dbcharset.', character_set_client=binary' : '';
				$serverset .= $this->version() > '5.0.1' ? ((empty($serverset) ? '' : ',').'sql_mode=\'\'') : '';
				$serverset && mysql_query("SET $serverset", $this->link);
			}
			$dbname && @mysql_select_db($dbname, $this->link);
		}

	}

	function query($sql, $type = '') {

		global $dbhost, $dbuser, $dbpw, $dbname, $pconnect,$dbcharset;
		$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query';
		if(!($query = $func($sql, $this->link))) {
			if(in_array($this->errno(), array(2006, 2013)) && substr($type, 0, 5) != 'RETRY') {
				$this->close();
				$this->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
				return $this->query($sql, 'RETRY'.$type);
			} elseif($type != 'SILENT' && substr($type, 5) != 'SILENT') {
				$this->halt('[err]MySQL Query Error[/err]'); //返回失败信息
			}
		}

		$this->querynum++;
		return $query;
	}

	function version() {
		if(empty($this->version)) {
			$this->version = mysql_get_server_info($this->link);
		}
		return $this->version;
	}
	
	function errno() {
		return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
	}

	function close() {
		return mysql_close($this->link);
	}
	
	function halt($message = '') {
		die($message);
	}
	
}

//====================================POST方式接收ET发来的参数======================================
$title=$_POST['title'];
$content=$_POST['content'];
$var1=$_POST['var1'];
$var2=$_POST['var2'];

//===================================对数据执行校验和整理=====================================
//
//根据需要增加处理代码
//
//=========================================数据入库===========================================
$db = new dbclass;
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
$db->query("INSERT INTO yourtable (title, content, var1, var2) VALUES ('$title', '$content', '$var1', '$var2')");
echo('[ok]');  //返回成功标记
$db->close();

?>