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

$dbhost = 'localhost';		// 数据库服务器，本地连接用localhost
$dbuser = 'root';			// 数据库用户名
$dbpw = 'yourpassword';		// 数据库密码
$dbname = 'yourdbname';		// 数据库名
$pconnect = 0;				// 数据库持久连接 0=关闭, 1=打开
$dbcharset = 'gbk';			// MySQL 字符集, 可选 'gbk', 'big5', 'utf8', 'latin1'
@header("Content-Type:text/html; charset=$dbcharset");
//=======================================数据库类=========================================
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 fetch_array($query, $result_type = MYSQL_ASSOC) {
		return mysql_fetch_array($query, $result_type);
	}



	function fetch_first($sql) {
		$query = $this->query($sql);
		return $this->fetch_array($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'];

//===================================对数据执行校验和整理=====================================
//
//根据需要增加处理代码
//
//=========================================在数据库查询标题是否重复===========================================
$db = new dbclass;
$db->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true, $dbcharset);
$query=$db->query("select * from yourtable where title='$title'  LIMIT 1");
if(!$query) {
 echo('[no]'); //返回无重复标记
}else{
 echo('[yes]'); //返回重复标记
}
$db->close();

?>