The pdo database and page class,please correction


<?php
class Dbo{
	protected $dbhost, $dbuser, $dbpwd, $dbname;
	public $conn, $record, $rTmp, $rPointer, $rTotal, $sql;
	public $pageSize, $currentPage, $pageTotal, $recordTotal, $oConnect;
	function __construct($sql='', $pageSize=0, $currentPage=''){
		$this->dbtype=DB_TYPE;
		$this->dbhost=DB_HOST;
		$this->dbuser=DB_USER;
		$this->dbpwd=DB_PASSWORD;
		$this->dbname=DB_NAME;
		$this->dbcharset=DB_CHARSET;
		$this->conn='';
		$this->sql=$sql;
		$this->record='';
		$this->rTmp='';
		$this->rArr=array();
		$this->rPointer=0;
		$this->rTotal=0;
		$this->pageSize=$pageSize;
		$this->currentPage=($currentPage=='')?$_GET["page"]:$currentPage;
		$this->pageTotal=0;
		$this->recordTotal=0;

		$this->openDB();
		if(!empty($sql))$this->qrySql($sql);
		if($pageSize)$this->page();
	}

	private function openDB(){
		$this->pdo=new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME, DB_USER, DB_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'GBK';")) or die("&#36830;&#25509;&#26381;&#21153;&#22120;&#22833;&#36133;:".$this->dbhost.':'.$this->dbuser);
	}

	public function runSql($sql){
//		$this->pdo->query('set names GBK;');
		$this->pdo->query($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[runSql]&#65306;".$sql);
	}

	public function qrySql($sql){
//		$this->pdo->query('set names GBK;');
		$this->record=$this->pdo->query($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[qrySql]&#65306;".$sql);
		return $this->record;
	}

	public function rNext(){
		$rArr=$this->record->fetch();
		return $rArr;
	}

	public function result_one($sql){
//		$this->pdo->query('set names GBK;');
		$rTmp=$this->pdo->query($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[result_one]&#65306;".$sql);
		$rArr=$rTmp->fetch();
		return $rArr[0];
	}

	public function result_onea($sql){
		$rTmp=$this->pdo->query($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[result_onea]&#65306;".$sql);
		$rArr=$rTmp->fetch();
		return $rArr;
	}

	public function result_all($sql){
		$rTmp=$this->pdo->query($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[result_all]&#65306;".$sql);
		$rArr=$rTmp->fetchAll();
		foreach($rArr as $rArrTmp){
			static $i=0;
			$arr[$i]=$rArrTmp[0];
			$i++;
		}
		return $arr;
	}

	public function fetch_all($sql){
		$rTmp=$this->pdo->query($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[fetch_all]&#65306;".$sql);
		$rArr=$rTmp->fetchAll();
		return $rArr;
	}

	//&#36890;&#36807;sql&#35821;&#21477;&#33719;&#21462;&#23383;&#27573;&#24635;&#25968;
	public function columnCount($sql){
		$p=$this->pdo->prepare($sql);
		$p->execute();
		$columnCount=$p->columnCount() or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[columnCount]&#65306;".$sql);
		return $columnCount;
	}

	public function getColumnName($tb){
		$sql='SHOW COLUMNS FROM '.$tb;
		$p = $this->pdo->prepare($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[getColumnName]&#65306;".$sql);
        try { 
			if($p->execute()){
				$raw_column_data = $p->fetchAll();
				foreach($raw_column_data as $outer_key => $array){
					foreach($array as $inner_key => $value){
						if ($inner_key === 'Field'){
							if (!(int)$inner_key){ 
								$column_namesArr[] = $value;
							}
						}
					}
				}
			}
			return $column_namesArr;
		}catch (Exception $e){                
			return $e->getMessage();      
		}
	}

	public function getColumnType($tb){
		$select = $DB->query('SELECT COUNT(*) FROM fruit');
		$meta = $select->getColumnMeta(0);
		var_dump($meta);

		$sql='SHOW COLUMNS FROM '.$tb;
		$p = $this->pdo->prepare($sql) or die("&#25191;&#34892;SQL&#35821;&#21477;&#20986;&#38169;[getColumnName]&#65306;".$sql);
        try { 
			if($p->execute()){
				$raw_column_data = $p->fetchAll();
				foreach($raw_column_data as $outer_key => $array){
					foreach($array as $inner_key => $value){
						if ($inner_key === 'Field'){
							if (!(int)$inner_key){ 
								$column_namesArr[] = $value;
							}
						}
					}
				}
			}
			return $column_namesArr;
		}catch (Exception $e){                
			return $e->getMessage(); //return exception        
		}
	}
/*
//mssql&#12289;mysql&#25968;&#25454;&#24211;&#36890;&#29992;&#20998;&#39029;
	function page(){
		$R=$this->record;
		if ($R){
			$this->recordTotal = $R->rowCount();
			$this->pageTotal = ceil($this->recordTotal/$this->pageSize);
			if ($this->currentPage>$this->pageTotal) $this->currentPage=$this->pageTotal;
			if (!$this->currentPage||$this->currentPage<=0) $this->currentPage=1;
			$begin = ( $this->currentPage-1 )   *   $this->pageSize;
			$ReArr=array();
			$index=0;
			if($this->pageSize>0) @mysql_data_seek($R,$begin);
			while($ResultArr=@$R->fetch()){
				if($this->pageSize>0){
					if($index>$this->pageSize-1) break;
					$ReArr[$index]=$ResultArr;
					$index++;
				}
			}
			return $ReArr;
		}else{
			return   false;
		}
	}
*/

	function page(){
		$R=$this->record;
		if ($R){
			$this->recordTotal = $R->rowCount();
			$this->pageTotal = ceil($this->recordTotal/$this->pageSize);
			if ($this->currentPage>$this->pageTotal) $this->currentPage=$this->pageTotal;
			if (!$this->currentPage||$this->currentPage<=0) $this->currentPage=1;
			$begin = ( $this->currentPage-1 ) * $this->pageSize;
			$this->record=$this->qrySql("$this->sql limit $begin, $this->pageSize") or die("&#20998;&#39029;&#26102;&#25171;&#24320;&#34920;&#22833;&#36133;1");
		}else{
			return false;
		}
	}

	function pagetip(){
		if(empty($this->currentPage) or $this->currentPage<0) $this->currentPage=1;
		if($this->currentPage>$this->pageTotal) $this->currentPage=$this->pageTotal;

		$links="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
		if(empty($_SERVER['QUERY_STRING'])){	//&#21028;&#26029;&#39318;&#27425;&#36827;&#20837;&#20998;&#39029;&#29366;&#24577;&#26102;&#26159;&#21542;&#23384;&#22312;&#21442;&#25968;
			$links=$links."?page=";
		}else{
			$links=preg_replace('(\\&?page=[0-9]+|page=[0-9]+\\&?)',"",$links);
			$links=$links."&page=";
		}

		echo "&#24635;".$this->recordTotal."&#26465; &#31532;".$this->currentPage."/".$this->pageTotal."&#39029; ";
		echo "<a style=color:#000000 href={$links}1>&#39318;&#39029;</a>&nbsp;";
		echo "<a style=color:#000000 href={$links}".($this->currentPage-1).">&#19978;&#19968;&#39029;</a>&nbsp;";
		echo "<a style=color:#000000 href={$links}".($this->currentPage+1).">&#19979;&#19968;&#39029;</a>&nbsp;";
		echo "<a style=color:#000000 href={$links}$this->pageTotal>&#23614;&#39029;</a>";
		echo "  <select name=menu1 onchange='window.location=this.options[this.selectedIndex].value'>";
		for($x=1;$x<=$this->pageTotal;$x++){
			if($x==$this->currentPage){
				echo "<option selected=selected value={$links}$x>".$x."</option>" ;
			}else{
				echo "<option value={$links}$x>".$x."</option>" ;
			}
		}
		echo "  </select>";
	}

}

/*
//&#25191;&#34892;&#35821;&#21477;&#33719;&#21462;&#35760;&#24405;
$dbo=new Dbo("select * from news order by taxis desc");
while($array=$dbo->rNext()){$id=$array['id']}

//&#25191;&#34892;&#35821;&#21477;&#26816;&#26597;&#26159;&#21542;&#23384;&#22312;&#35760;&#24405;
$dbo=new Dbo();
$chkExists=$dbo->result_one("select count(id) from newssort where fcode=''")
if($chkExists){};

//&#20998;&#39029;&#35843;&#29992;&#26041;&#24335;1(&#21487;&#29992;&#20110;PHP+MSSQL&#65292;&#20351;&#29992;mssql&#12289;mysql&#25968;&#25454;&#24211;&#36890;&#29992;&#20998;&#39029;&#20989;&#25968;&#26102;)&#65306;
$pageSize=10;
$Pdbo=new Dbo("select * from news order by taxis desc,id desc", $pageSize);
$rArr=$Pdbo->page();
for($i=0; $i<count($rArr); $i++){
	$array=$rArr[$i];
	$id=$array["id"];
	$listNum=($Pdbo->currentPage-1)*$pageSize+$i+1;
}

//&#20998;&#39029;&#35843;&#29992;&#26041;&#24335;2&#65306;
$pageSize=10;
$Pdbo=new Dbo("select * from news order by taxis desc,id desc", $pageSize);
while($array=$Pdbo->rNext()){
	static $i=1;
	$id=$array["id"];
	$listNum=($Pdbo->currentPage-1)*$pageSize+$i;
	$i++;
}
*/
?>