<?
php
require_once ( " sys_info.php " );
// 文件名:ClassDataBase.php
//类名:数据库类 ClassDataBase
//作者:感染源
//日期:2007-1-4
class ClassDataBase
{
// 属性
private $host ; // 数据库主机名
private $user ; // 用户名
private $pwd ; // 密码
private $dbname ; // 数据库名
private $ConnId ; // 数据库链接标识
private $db_selected ; // 数据库选择标识
private $result ; // 数据库查询返回结构集
//构造函数,链接数据库
function __construct()
{
$this -> host = sys_info :: $HOST ;
$this -> user = sys_info :: $USER ;
$this -> pwd = sys_info :: $PWD ;
$this -> dbname = sys_info :: $DBNAME ;
// 链接数据库
$this -> ConnId = mysql_connect ( $this -> host , $this -> user , $this -> pwd);
if ( ! $this -> ConnId)
{
die ( ' Sorry,Connect database false! ' . mysql_error ());
}
else
{
// 选择数据库
$this -> db_selected = mysql_select_db ( $this -> dbname , $this -> ConnId);
if ( ! $this -> db_selected)
{
die ( ' Can't select the database: ' . mysql_error ());
} // if;
} // if;
} // function __construct();
//析构函数,关闭数据库
function __destruct()
{
// 关闭数据库链接
mysql_close ( $this -> ConnId);
} // function __destruct();
//执行数据库的更新,插入和删除
function ExecuteSQL( $sql )
{
$this -> result = mysql_query ( $sql );
if ( ! $this -> result)
{
die ( ' Can't update the database: ' . mysql_error ());
} // if
} // function ExecuteSQL();
//执行数据库的查询,并返回查询结果
function QuerySQL( $sql )
{
$i = 0 ;
$result_arr = array ();
$this -> result = mysql_query ( $sql , $this -> ConnId);
if ( ! $this -> result)
{
die ( ' Can't view the database: ' . mysql_error ());
}
else
{
while ( $row = mysql_fetch_array ( $this -> result))
{
$result_arr [ $i ++ ] = $row ;
} // while
return $result_arr ;
// 释放内存
mysql_free_result ( $this -> result);
} // if
} // function QuerySQL();
} // ClassDataBase;
?>
<? php
// 文件名:sys_info.inc
//类名:环境变量类 sys_info
//作者:感染源
//时间:2007-1-4
class sys_info
{
public static $HOST = " localhost " ; // MySql Host Name
public static $USER = " root " ; // MySql Login Name
public static $PWD = " root " ; // MySql Login Password
public static $DBNAME = " books " ; // 数据库名
public static $MAX_LINE = 5 ; // 每页显示最多行数
} // class sys_info;
?>
require_once ( " sys_info.php " );
// 文件名:ClassDataBase.php
//类名:数据库类 ClassDataBase
//作者:感染源
//日期:2007-1-4
class ClassDataBase
{
// 属性
private $host ; // 数据库主机名
private $user ; // 用户名
private $pwd ; // 密码
private $dbname ; // 数据库名
private $ConnId ; // 数据库链接标识
private $db_selected ; // 数据库选择标识
private $result ; // 数据库查询返回结构集
//构造函数,链接数据库
function __construct()
{
$this -> host = sys_info :: $HOST ;
$this -> user = sys_info :: $USER ;
$this -> pwd = sys_info :: $PWD ;
$this -> dbname = sys_info :: $DBNAME ;
// 链接数据库
$this -> ConnId = mysql_connect ( $this -> host , $this -> user , $this -> pwd);
if ( ! $this -> ConnId)
{
die ( ' Sorry,Connect database false! ' . mysql_error ());
}
else
{
// 选择数据库
$this -> db_selected = mysql_select_db ( $this -> dbname , $this -> ConnId);
if ( ! $this -> db_selected)
{
die ( ' Can't select the database: ' . mysql_error ());
} // if;
} // if;
} // function __construct();
//析构函数,关闭数据库
function __destruct()
{
// 关闭数据库链接
mysql_close ( $this -> ConnId);
} // function __destruct();
//执行数据库的更新,插入和删除
function ExecuteSQL( $sql )
{
$this -> result = mysql_query ( $sql );
if ( ! $this -> result)
{
die ( ' Can't update the database: ' . mysql_error ());
} // if
} // function ExecuteSQL();
//执行数据库的查询,并返回查询结果
function QuerySQL( $sql )
{
$i = 0 ;
$result_arr = array ();
$this -> result = mysql_query ( $sql , $this -> ConnId);
if ( ! $this -> result)
{
die ( ' Can't view the database: ' . mysql_error ());
}
else
{
while ( $row = mysql_fetch_array ( $this -> result))
{
$result_arr [ $i ++ ] = $row ;
} // while
return $result_arr ;
// 释放内存
mysql_free_result ( $this -> result);
} // if
} // function QuerySQL();
} // ClassDataBase;
?>
<? php
// 文件名:sys_info.inc
//类名:环境变量类 sys_info
//作者:感染源
//时间:2007-1-4
class sys_info
{
public static $HOST = " localhost " ; // MySql Host Name
public static $USER = " root " ; // MySql Login Name
public static $PWD = " root " ; // MySql Login Password
public static $DBNAME = " books " ; // 数据库名
public static $MAX_LINE = 5 ; // 每页显示最多行数
} // class sys_info;
?>