Mysql_User_Domain_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:6k
- <?php
- class Mysql_User_Domain_Db extends BaseObject {
- var $debug;
- var $user_domain_db;
- Function Mysql_User_Domain_Db( $db_config = '' ) {
- $this->BaseObject( 'Mysql_User_Domain_Db' );
- $this->user_domain_db = new Mysql_Db();
- if ( is_object( $db_config ) ) {
- $this->user_domain_db->db = $db_config;
- }
- $this->debug = new Debug();
- $this->debug->prefix = 'Mysql_Db::Mysql_User_Domain';
- $this->debug->Off();
- $this->user_domain_db->debug->Off();
- }
- Function InitDbConnection() {
- /*
- Make sure the database handle is available
- ( if not try to open it )
- */
- $returns = Array();
- if ( $this->user_domain_db->connection_init == false) {
- $returns = $this->user_domain_db->CreateConnection();
- }
- /* Oh no we failed to open the connection */
- if ( $this->user_domain_db->connection_init == false ) {
- return array( false, 'Database not connected', $returns );
- }
- return array( true );
- }
- Function ListAll() {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $sql_util = new SqlUtil();
- /* Look ma no hands, and out comes a nice formated sql */
- $get_domain = $this->user_domain_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'domain_table' ),
- Array( 'domain_id', 'domain_name' ),
- ''
- )
- );
- $t_array = Array();
- $t_cnt = 0;
- while( list( $domain_id, $domain_name ) = $get_domain->FetchRow() ) {
- $domain_obj = new User_Domain();
- $domain_obj->domain_id = $domain_id;
- $domain_obj->domain_name = $domain_name;
- $t_array[ $t_cnt ] = $domain_obj;
- $t_cnt++;
- }
- return Array( true, $t_cnt, $t_array );
- }
- Function Add( $domain_obj ) {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $sql_util = new SqlUtil();
- /* Look ma no hands, and out comes a nice formated sql */
- $insert_domain = $this->user_domain_db->PrepareSql(
- $sql_util->InsertStatement(
- 'domain_table',
- Array(
- 'domain_id' => $domain_obj->domain_id,
- 'domain_name' => $domain_obj->domain_name
- )
- )
- );
- list( $ret_val, $reason ) = $insert_domain->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Insert to table failed.' );
- } else {
- return Array( true );
- }
- } /* End add */
- Function Delete( $domain_id) {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $sql_util = new SqlUtil();
- /* Look ma no hands, and out comes a nice formated sql */
- $delete_domain = $this->user_domain_db->PrepareSql(
- $sql_util->DeleteStatement(
- 'domain_table',
- 'domain_id = ' . $domain_id
- )
- );
- list( $ret_val, $reason ) = $delete_domain->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Delete of domain failed.' );
- } else {
- return Array( true );
- }
- }
- Function Get( $domain_id ) {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $sql_util = new SqlUtil();
- /* Look ma no hands, and out comes a nice formated sql */
- $get_domain = $this->user_domain_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'domain_table' ),
- Array( 'domain_id', 'domain_name' ),
- 'domain_id = ' . $domain_id
- )
- );
- if ( ! (
- list( $domain_id, $domain_name ) = $get_domain->FetchRow()
- ) ) {
- return Array( false, 'No match found.' );
- } else {
- $domain_obj = new User_Domain();
- $domain_obj->domain_id = $domain_id;
- $domain_obj->domain_name = $domain_name;
- return Array( true, $domain_obj );
- }
- }
- Function Modify( $domain_obj ) {
- /* Make sure the database handle is available */
- /* Init the database connection and bubble up errors */
- $this->debug->Message( 'Init connection' );
- list( $ret_val, $reason ) = $this->InitDbConnection();
- if ( $ret_val == false ) {
- $this->debug->Message( 'connect failed' );
- return array( $ret_val, $reason );
- }
- $sql_util = new SqlUtil();
- /* Look ma no hands, and out comes a nice formated sql */
- $update_domain = $this->user_domain_db->PrepareSql(
- $sql_util->UpdateStatement(
- 'domain_table',
- Array(
- 'domain_name' => $domain_obj->domain_name
- ),
- 'domain_id = ' . $domain_obj->domain_id
- )
- );
- list( $ret_val, $reason ) = $update_domain->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Update of domain failed.' );
- } else {
- return Array( true );
- }
- }
- }
- ?>