Mysql_CustomerAddress_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:9k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class Mysql_CustomerAddress_Db extends BaseObject {
  3.    var $debug;
  4.    var $customer_db;
  5.    Function Mysql_CustomerAddress_Db( $db_config ) {
  6.       $this->BaseObject( 'Mysql_CustomerAddress_Db' );
  7.       $this->customer_db = new Mysql_Db();
  8.       if ( is_object( $db_config ) ) {
  9.          $this->customer_db->db = $db_config;
  10.       }
  11.       $this->debug            = new Debug();
  12.       $this->debug->prefix    = 'Mysql_Db::Mysql_CustomerAddress';
  13.       $this->debug->On();
  14.       $this->customer_db->debug->On();
  15.    }
  16.    Function InitDbConnection() {
  17.       /*
  18.         Make sure the database handle is available 
  19.         ( if not try to open it ) 
  20.       */
  21.       $returns = Array();
  22.       if ( $this->customer_db->connection_init == false) {
  23.          $returns = $this->customer_db->CreateConnection();
  24.       }
  25.       /* Oh no we failed to open the connection */
  26.       if ( $this->customer_db->connection_init == false ) {
  27.          return array( false, 'Database not connected', $returns );
  28.       }
  29.       return array( true );
  30.    }
  31.     Function Add( $address_obj ) {
  32.       /* Make sure the database handle is available */
  33.       /* Init the database connection and bubble up errors */
  34.       $this->debug->Message( 'Init connection' );
  35.       list( $ret_val, $reason ) = $this->InitDbConnection();
  36.       if ( $ret_val == false ) {
  37.       $this->debug->Message( 'connect failed' );
  38.          return array( $ret_val, $reason );
  39.       }
  40.       $sql_util = new SqlUtil();
  41.       /* Look ma no hands, and out comes a nice formated sql */
  42.       $insert_address = $this->customer_db->PrepareSql(
  43.          $sql_util->InsertStatement(
  44.             'address_table',
  45.             Array(
  46.                'user_id'         => $address_obj->user_id,
  47.                'address_name'    => $address_obj->address_name,
  48.                'address'         => $address_obj->address,
  49.                'city'            => $address_obj->city,
  50.                'state'           => $address_obj->state,
  51.                'zip'             => $address_obj->zip,
  52.                'country'         => $address_obj->country,
  53.                'mailing_address' => $address_obj->mailing_address,
  54.                'last_update_by'  => $address_obj->last_update_by,
  55.                'last_update'     => $address_obj->last_update
  56.             )
  57.          )
  58.       );
  59.       list( $ret_val, $reason ) = $insert_address->Exec();
  60.       if ( ! $ret_val ) {
  61.          return Array( false, 'Insert to table failed.' );
  62.       } else {
  63.          return Array( true );
  64.       }
  65.    } /* End add */
  66.    Function ListAll( $user_id )    { 
  67.       /* Make sure the database handle is available */
  68.       /* Init the database connection and bubble up errors */
  69.       $this->debug->Message( 'Init connection' );
  70.       list( $ret_val, $reason ) = $this->InitDbConnection();
  71.       if ( $ret_val == false ) {
  72.       $this->debug->Message( 'connect failed' );
  73.          return array( $ret_val, $reason );
  74.       }
  75.       $sql_util = new SqlUtil();
  76.       /* Look ma no hands, and out comes a nice formated sql */
  77.       $get_addresses = $this->customer_db->PrepareSql(
  78.          $sql_util->SelectStatement(
  79.             Array( 'address_table' ),
  80.             Array(
  81.                'address_id',
  82.                'user_id',           'address_name',
  83.                'address',           'city',
  84.                'state',             'zip',
  85.                'country',           'mailing_address',
  86.                'last_update_by',    'last_update'
  87.             ),
  88.             'user_id = ' . $user_id
  89.          )
  90.       );
  91.       $t_array = Array();
  92.       while( list( 
  93.                $address_id,
  94.                $user_id,           $address_name,
  95.                $address,           $city,
  96.                $state,             $zip,
  97.                $country,           $mailing_address,
  98.                $last_update_by,    $last_update
  99.             ) = $get_addresses->FetchRow() ) {
  100.          $t_obj = new CustomerAddress();
  101.          $t_obj->address_id      = $address_id;
  102.          $t_obj->user_id         = $user_id;
  103.          $t_obj->address_name    = $address_name;
  104.          $t_obj->address         = $address;
  105.          $t_obj->city            = $city;
  106.          $t_obj->state           = $state;
  107.          $t_obj->zip             = $zip;
  108.          $t_obj->country         = $country;
  109.          $t_obj->mailing_address = $mailing_address;
  110.          $t_obj->last_update_by  = $last_update_by;
  111.          $t_obj->last_update     = $last_update;
  112.          $t_array[] = $t_obj;
  113.       }
  114.       return $t_array;
  115.    }
  116.    Function Get( $address_id )    { 
  117.       /* Make sure the database handle is available */
  118.       /* Init the database connection and bubble up errors */
  119.       $this->debug->Message( 'Init connection' );
  120.       list( $ret_val, $reason ) = $this->InitDbConnection();
  121.       if ( $ret_val == false ) {
  122.       $this->debug->Message( 'connect failed' );
  123.          return array( $ret_val, $reason );
  124.       }
  125.       $sql_util = new SqlUtil();
  126.       /* Look ma no hands, and out comes a nice formated sql */
  127.       $get_addresses = $this->customer_db->PrepareSql(
  128.          $sql_util->SelectStatement(
  129.             Array( 'address_table' ),
  130.             Array(
  131.                'address_id',
  132.                'user_id',           'address_name',
  133.                'address',           'city',
  134.                'state',             'zip',
  135.                'country',           'mailing_address',
  136.                'last_update_by',    'last_update'
  137.             ),
  138.             'address_id = ' . $address_id
  139.          )
  140.       );
  141.       $t_array = Array();
  142.       list( $address_id,   $user_id,           $address_name,
  143.             $address,      $city,              $state,
  144.             $zip,          $country,           $mailing_address,
  145.             $last_update_by,    $last_update
  146.             ) = $get_addresses->FetchRow();
  147.    
  148.      $t_obj = new CustomerAddress();
  149.      $t_obj->address_id      = $address_id;
  150.      $t_obj->user_id         = $user_id;
  151.      $t_obj->address_name    = $address_name;
  152.      $t_obj->address         = $address;
  153.      $t_obj->city            = $city;
  154.      $t_obj->state           = $state;
  155.      $t_obj->zip             = $zip;
  156.      $t_obj->country         = $country;
  157.      $t_obj->mailing_address = $mailing_address;
  158.      $t_obj->last_update_by  = $last_update_by;
  159.      $t_obj->last_update     = $last_update;
  160.      return $t_obj;
  161.    }
  162.   Function Delete( $address_id ) { 
  163.       /* Make sure the database handle is available */
  164.       /* Init the database connection and bubble up errors */
  165.       $this->debug->Message( 'Init connection' );
  166.       list( $ret_val, $reason ) = $this->InitDbConnection();
  167.       if ( $ret_val == false ) {
  168.       $this->debug->Message( 'connect failed' );
  169.          return array( $ret_val, $reason );
  170.       }
  171.       $sql_util = new SqlUtil();
  172.       /* Look ma no hands, and out comes a nice formated sql */
  173.       $delete_domain = $this->customer_db->PrepareSql(
  174.          $sql_util->DeleteStatement(
  175.             'address_table',
  176.             'address_id = ' . $address_id
  177.          )
  178.       );
  179.       list( $ret_val, $reason ) = $delete_domain->Exec();
  180.       if ( ! $ret_val ) {
  181.          return Array( false, 'Delete of address failed.' );
  182.       } else {
  183.          return Array( true );
  184.       }
  185.    }
  186.    Function Modify( $address_obj ) {
  187.       /* Make sure the database handle is available */
  188.       /* Init the database connection and bubble up errors */
  189.       $this->debug->Message( 'Init connection' );
  190.       list( $ret_val, $reason ) = $this->InitDbConnection();
  191.       if ( $ret_val == false ) {
  192.       $this->debug->Message( 'connect failed' );
  193.          return array( $ret_val, $reason );
  194.       }
  195.       $sql_util = new SqlUtil();
  196.       /* Look ma no hands, and out comes a nice formated sql */
  197.       $update_domain = $this->customer_db->PrepareSql(
  198.          $sql_util->UpdateStatement(
  199.             'address_table',
  200.             Array(
  201.                'user_id'               => $address_obj->user_id,
  202.                'address_name'          => $address_obj->address_name,
  203.                'address'               => $address_obj->address,
  204.                'city'                  => $address_obj->city,
  205.                'state'                 => $address_obj->state,
  206.                'zip'                   => $address_obj->zip,
  207.                'country'               => $address_obj->country,
  208.                'mailing_address'       => $address_obj->mailing_address,
  209.                'last_update_by'        => $address_obj->last_update_by,
  210.                'last_update'           => $address_obj->last_update
  211.             ),
  212.             'address_id = ' . $address_obj->address_id
  213.          )
  214.       );
  215.       list( $ret_val, $reason ) = $update_domain->Exec();
  216.       if ( ! $ret_val ) {
  217.          return Array( false, 'Update of domain failed.' );
  218.       } else {
  219.          return Array( true );
  220.       }
  221.    }
  222. }
  223. ?>