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

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class Mysql_CustomerPhoneNumber_Db extends BaseObject {
  3.    var $debug;
  4.    var $customer_db;
  5.    Function Mysql_CustomerPhoneNumber_Db( $db_config ) {
  6.       $this->BaseObject( 'Mysql_CustomerPhoneNumber_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_CustomerPhoneNumber';
  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( $phone_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_phone = $this->customer_db->PrepareSql(
  43.          $sql_util->InsertStatement(
  44.             'phone_num_table',
  45.             Array(
  46.                'user_id'               => $phone_obj->user_id,
  47.                'phone_number_name'     => $phone_obj->phone_number_name,
  48.                'phone_number'          => $phone_obj->phone_number,
  49.                'phone_number_notes'    => $phone_obj->phone_number_notes,
  50.                'contact_number'        => $phone_obj->contact_number
  51.             )
  52.          )
  53.       );
  54.       list( $ret_val, $reason ) = $insert_phone->Exec();
  55.       if ( ! $ret_val ) {
  56.          return Array( false, 'Insert to table failed.' );
  57.       } else {
  58.          return Array( true );
  59.       }
  60.    } /* End add */
  61.    Function ListAll( $user_id )    { 
  62.       /* Make sure the database handle is available */
  63.       /* Init the database connection and bubble up errors */
  64.       $this->debug->Message( 'Init connection' );
  65.       list( $ret_val, $reason ) = $this->InitDbConnection();
  66.       if ( $ret_val == false ) {
  67.       $this->debug->Message( 'connect failed' );
  68.          return array( $ret_val, $reason );
  69.       }
  70.       $sql_util = new SqlUtil();
  71.       /* Look ma no hands, and out comes a nice formated sql */
  72.       $get_phones = $this->customer_db->PrepareSql(
  73.          $sql_util->SelectStatement(
  74.             Array( 'phone_num_table' ),
  75.             Array(
  76.                'phone_num_id',               'user_id',
  77.                'phone_number_name',          'phone_number',
  78.                'phone_number_notes',         'contact_number'
  79.             ),
  80.             'user_id = ' . $user_id
  81.          )
  82.       );
  83.       $t_array = Array();
  84.       while( list(
  85.                $phone_num_id,               $user_id,
  86.                $phone_number_name,          $phone_number,
  87.                $phone_number_notes,         $contact_number
  88.             ) = $get_phones->FetchRow() ) {
  89.          $t_obj = new CustomerPhoneNumber();
  90.          $t_obj->phone_num_id       = $phone_num_id;
  91.          $t_obj->user_id            = $user_id;
  92.          $t_obj->phone_number_name  = $phone_number_name;
  93.          $t_obj->phone_number       = $phone_number;
  94.          $t_obj->phone_number_notes = $phone_number_notes;
  95.          $t_obj->contact_number     = $contact_number;
  96.          $t_array[] = $t_obj;
  97.       }
  98.       return $t_array;
  99.    }
  100.    Function Get( $phone_id )    { 
  101.       /* Make sure the database handle is available */
  102.       /* Init the database connection and bubble up errors */
  103.       $this->debug->Message( 'Init connection' );
  104.       list( $ret_val, $reason ) = $this->InitDbConnection();
  105.       if ( $ret_val == false ) {
  106.       $this->debug->Message( 'connect failed' );
  107.          return array( $ret_val, $reason );
  108.       }
  109.       $sql_util = new SqlUtil();
  110.       /* Look ma no hands, and out comes a nice formated sql */
  111.       $get_phones = $this->customer_db->PrepareSql(
  112.          $sql_util->SelectStatement(
  113.             Array( 'phone_num_table' ),
  114.             Array(
  115.                'phone_num_id',               'user_id',
  116.                'phone_number_name',          'phone_number',
  117.                'phone_number_notes',         'contact_number'
  118.             ),
  119.             'phone_num_id = ' . $phone_id
  120.          )
  121.       );
  122.       $t_array = Array();
  123.       list( $phone_num_id,               $user_id,
  124.             $phone_number_name,          $phone_number,
  125.             $phone_number_notes,         $contact_number
  126.             ) = $get_phones->FetchRow();
  127.      $t_obj = new CustomerPhoneNumber();
  128.      $t_obj->phone_num_id       = $phone_num_id;
  129.      $t_obj->user_id            = $user_id;
  130.      $t_obj->phone_number_name  = $phone_number_name;
  131.      $t_obj->phone_number       = $phone_number;
  132.      $t_obj->phone_number_notes = $phone_number_notes;
  133.      $t_obj->contact_number     = $contact_number;
  134.      return $t_obj;
  135.    }
  136.   Function Delete( $phone_id ) { 
  137.       /* Make sure the database handle is available */
  138.       /* Init the database connection and bubble up errors */
  139.       $this->debug->Message( 'Init connection' );
  140.       list( $ret_val, $reason ) = $this->InitDbConnection();
  141.       if ( $ret_val == false ) {
  142.       $this->debug->Message( 'connect failed' );
  143.          return array( $ret_val, $reason );
  144.       }
  145.       $sql_util = new SqlUtil();
  146.       /* Look ma no hands, and out comes a nice formated sql */
  147.       $delete_phone = $this->customer_db->PrepareSql(
  148.          $sql_util->DeleteStatement(
  149.             'phone_num_table',
  150.             'phone_num_id = ' . $phone_id
  151.          )
  152.       );
  153.       list( $ret_val, $reason ) = $delete_phone->Exec();
  154.       if ( ! $ret_val ) {
  155.          return Array( false, 'Delete of phone failed.' );
  156.       } else {
  157.          return Array( true );
  158.       }
  159.    }
  160.    Function Modify( $phone_obj ) {
  161.       /* Make sure the database handle is available */
  162.       /* Init the database connection and bubble up errors */
  163.       $this->debug->Message( 'Init connection' );
  164.       list( $ret_val, $reason ) = $this->InitDbConnection();
  165.       if ( $ret_val == false ) {
  166.       $this->debug->Message( 'connect failed' );
  167.          return array( $ret_val, $reason );
  168.       }
  169.       $sql_util = new SqlUtil();
  170.       /* Look ma no hands, and out comes a nice formated sql */
  171.       $update_domain = $this->customer_db->PrepareSql(
  172.          $sql_util->UpdateStatement(
  173.             'phone_num_table',
  174.             Array(
  175.                'user_id'               => $phone_obj->user_id,
  176.                'phone_number_name'     => $phone_obj->phone_number_name,
  177.                'phone_number'          => $phone_obj->phone_number,
  178.                'phone_number_notes'    => $phone_obj->phone_number_notes,
  179.                'contact_number'        => $phone_obj->contact_number
  180.             ),
  181.             'phone_num_id = ' . $phone_obj->phone_num_id
  182.          )
  183.       );
  184.       list( $ret_val, $reason ) = $update_domain->Exec();
  185.       if ( ! $ret_val ) {
  186.          return Array( false, 'Update of phone failed.' );
  187.       } else {
  188.          return Array( true );
  189.       }
  190.    }
  191. }
  192. ?>