$x_db 所用到的数据库类
/*****
// +-------------------------------------------------
// | Id: vbf_db.php
// +-------------------------------------------------
// | Copyright (c)
// | Author:Arvan
// +-------------------------------------------------
// | Create Date: 2003-6-23
// | Modify Date:
// | Note:
// | 数据库操作的类
// |
// |
// +-------------------------------------------------
*****/
class TDb{
var $host;
var $user;
var $password;
var $database;
var $n;
var $result="";
var $conn="";
var $debug = true;
var $errMsg = "";
function TDb($host,$user,$password,$database){
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->conn=@mysql_connect($host,$user,$password) or die("<br><br><b>Err:</b>SQL busy,please try again later!");
$this->set_db($database);
$this->errMsg ="";
$this->n = 0;
}
//end of func tdb
function exec($sql, $db_name = ''){
if (($db_name != '') && ($db_name != $this->database)){
$old_db = $this->database;
$this->set_db($db_name);
}
$this->n = 0;
$this->result=@mysql_query($sql,$this->conn);
if (mysql_error() != ""){
$this->errMsg = mysql_error();
if ($this->debug){
echo "<br><br><b>Err:</b>Fail to execute this SQL query:$sql<br><br>$this->errMsg";
}else{
echo "<br><br><br><b>Err:</b>Please check the query is normal and make sure that It's allowed!";
}
exit;
}
$this->n = @mysql_affected_rows();
if($old_db != ''){
$this->set_db($old_db);
}
return true;
}
function get_data(){
if($this->result==""){
echo "<br><br><b>Err:</b>There is no result please run method exec(\$sql) first";
exit;
}
$count=0;
while($row=mysql_fetch_array($this->result)){
$data[$count]=$row;
$count++;
}
mysql_free_result($this->result);
return $data;
}
//end of func get_data
function get_ins_id(){
return mysql_insert_id();
}
function free(){
mysql_close($this->conn);
}
function set_db($db_name){
if($db_name != $this->database){//select new table while they are different
@mysql_select_db($db_name) or die("<br><b>Err:</b>Fail to select $db_name table, make sure it's allowed to do this!");
$this->database=$db_name;
}
return true;
}
function get_cur_db(){
return $this->database;
}
}
//End of class db
// +-------------------------------------------------
// | Id: vbf_db.php
// +-------------------------------------------------
// | Copyright (c)
// | Author:Arvan
// +-------------------------------------------------
// | Create Date: 2003-6-23
// | Modify Date:
// | Note:
// | 数据库操作的类
// |
// |
// +-------------------------------------------------
*****/
class TDb{
var $host;
var $user;
var $password;
var $database;
var $n;
var $result="";
var $conn="";
var $debug = true;
var $errMsg = "";
function TDb($host,$user,$password,$database){
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->conn=@mysql_connect($host,$user,$password) or die("<br><br><b>Err:</b>SQL busy,please try again later!");
$this->set_db($database);
$this->errMsg ="";
$this->n = 0;
}
//end of func tdb
function exec($sql, $db_name = ''){
if (($db_name != '') && ($db_name != $this->database)){
$old_db = $this->database;
$this->set_db($db_name);
}
$this->n = 0;
$this->result=@mysql_query($sql,$this->conn);
if (mysql_error() != ""){
$this->errMsg = mysql_error();
if ($this->debug){
echo "<br><br><b>Err:</b>Fail to execute this SQL query:$sql<br><br>$this->errMsg";
}else{
echo "<br><br><br><b>Err:</b>Please check the query is normal and make sure that It's allowed!";
}
exit;
}
$this->n = @mysql_affected_rows();
if($old_db != ''){
$this->set_db($old_db);
}
return true;
}
function get_data(){
if($this->result==""){
echo "<br><br><b>Err:</b>There is no result please run method exec(\$sql) first";
exit;
}
$count=0;
while($row=mysql_fetch_array($this->result)){
$data[$count]=$row;
$count++;
}
mysql_free_result($this->result);
return $data;
}
//end of func get_data
function get_ins_id(){
return mysql_insert_id();
}
function free(){
mysql_close($this->conn);
}
function set_db($db_name){
if($db_name != $this->database){//select new table while they are different
@mysql_select_db($db_name) or die("<br><b>Err:</b>Fail to select $db_name table, make sure it's allowed to do this!");
$this->database=$db_name;
}
return true;
}
function get_cur_db(){
return $this->database;
}
}
//End of class db
[1] [2]
