MYSQL连接类:
<?php
class mySQL{
var $username;
var $password;
var $connectionInfo;
var $conn;
//connection constructor
public function mySQL($dbname,$username,$password){
$this->username=$username;
$this->password=$password;
$this->connectionInfo="mysql:host=localhost;dbname=".$dbname;
}
public function getConnection(){
$this->conn= new PDO($this->connectionInfo,$this->username,$this->password,array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES 'GBK';"));
$this->conn->exec("SET CHARACTER SET GBK");
//$this->conn->exec("SET NAMES 'GBK';");
return $this->conn;
}
public function terminateConn(){
$this->conn=null;
}
public function getConnectionInfo(){
print $this->username." :usernmae<br>";
print $this->password." :password<br>";
print $this->connectionInfo." :connection information<br>";
print $this->conn." :connection drives<br>";
}
}
?>
<?php
class mySQL{
var $username;
var $password;
var $connectionInfo;
var $conn;
//connection constructor
public function mySQL($dbname,$username,$password){
$this->username=$username;
$this->password=$password;
$this->connectionInfo="mysql:host=localhost;dbname=".$dbname;
}
public function getConnection(){
$this->conn= new PDO($this->connectionInfo,$this->username,$this->password,array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET NAMES 'GBK';"));
$this->conn->exec("SET CHARACTER SET GBK");
//$this->conn->exec("SET NAMES 'GBK';");
return $this->conn;
}
public function terminateConn(){
$this->conn=null;
}
public function getConnectionInfo(){
print $this->username." :usernmae<br>";
print $this->password." :password<br>";
print $this->connectionInfo." :connection information<br>";
print $this->conn." :connection drives<br>";
}
}
?>
?php
include 'mySQL.class.php';
include 'Server.class.php';
include 'memberstruct.class.php';
include 'CurrentPage.class.php';
include 'charactertest.php';
include 'comparecharacter.php';
include 'untilfunction.php';
include 'optionconfig.php';
header("Content-Type=text/html;Charset=GBK");
set_time_limit(0);
$pageNumber=intval($_GET['page']);
$strPageSize=$singleTarget; if(empty($_COOKIE['myHost'])){
echo '<script type="text/javascript">window.location.replace("index.html");</script>';
}
$conn=new LinkServer($dbhost,$dbname,$dbuser,$dbpassword);
$connSQLSERVER=$conn->getConnection();
$tSQL="SELECT DISTINCT e1.AccountName AS accountName, e2.Birthday AS birthday, e2.QQ AS qq, e2.MSN AS msn, e2.Gender AS sex, e2.Blood AS blood,
e2.NickName AS spaceName FROM t_Character AS e2 INNER JOIN t_User AS e1 ON e2.AccountID = e1.AccountID WHERE (e1.AccountName IS NOT NULL)";
//instance page object
$pageRecord=new CurrentPage($connSQLSERVER,$tSQL,$strPageSize,$pageNumber);
//close current connection
$conn->terminateConn();
//get recordset
$arrTemp=$pageRecord->getRecordSet();
//check current state
$pageRecord->checkCurrentState($pageNumber,"control.php?model=character&state=access");
//traverse result
for($i=0;$i<count($arrTemp);$i++){
//replace insert functiin
$tempUser=substr(replaceVarWhite($arrTemp[$i]->accountName),0,14);
//print $tempUser."<br>";
list($strYear,$strMonth, $strDay) = split ('[/.-]', date('Y-m-d',GetTimeStamp($arrTemp[$i]->birthday)));
$strQQ=$arrTemp[$i]->qq;
$strMSN=$arrTemp[$i]->msn;
$strSex=$arrTemp[$i]->sex;
$strBlood=replaceBloodStr($arrTemp[$i]->blood);
$strSpaceName=$arrTemp[$i]->spaceName;
/*
echo $tempUser."<br>";
echo $strYear."-".$strMonth."-".$strDay."<br>";
echo $strQQ."<br>";
echo $strMSN."<br>";
echo $strSex."<br>";
echo $strBlood."<br>";
echo $strSpaceName."<br><br>";
*/
compareCharacter($tempUser,$strYear,$strMonth,$strDay,$strQQ,$strMSN,$strSex,$strBlood,$strSpaceName);
}
//if has next page jump next page
$pageRecord->jumpCurrentPage();
?>