1 <?php 2 class DB{ 3 var $host; 4 var $user; 5 var $pwd; 6 var $dbname; 7 var $conn; 8 9 function DB($host,$user,$pwd,$dbname){ 10 $this->host = $host; 11 $this->user = $user; 12 $this->pwd = $pwd; 13 $this->dbname = $dbname; 14 } 15 16 function GetConn(){ 17 $this->conn = mysql_connect($this->host,$this->user,$this->pwd,$this->dbname) or die("数据库服务器连接失败".mysql_errno()); 18 mysql_select_db($this->dbname,$this->conn) or die("数据库选择失败".mysql_errno()); 19 mysql_query("SET NAMES ‘UTF8‘"); 20 mysql_query("SET CHARACTER SET UTF8"); 21 mysql_query("SET CHARACTER_SET_RESULTS=UTF8‘"); 22 return $this->conn; 23 } 24 25 function CloseConnld(){ 26 mysql_close($this->conn); 27 } 28 } 29 ?>
<?php class AdminDB{ function ExecSQL($sql,$conn){ $sqltype = strtolower(substr(trim($sql), 0, 6)); $rs = mysql_query($sql); if($sqltype == "select"){ $array = array(); while($row = mysql_fetch_array($rs)){ array_push($array,$row); } if($rs == false) return false; else return $array; }else if($sqltype == "update" || $sqltype == "delete" || $sqltype == "insert"){ if($rs) return true; else return false; } } } ?>