Mysql_CustomerAddress_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:9k
源码类别:
WEB邮件程序
开发平台:
PHP
- <?php
- class Mysql_CustomerAddress_Db extends BaseObject {
- var $debug;
- var $customer_db;
- Function Mysql_CustomerAddress_Db( $db_config ) {
- $this->BaseObject( 'Mysql_CustomerAddress_Db' );
- $this->customer_db = new Mysql_Db();
- if ( is_object( $db_config ) ) {
- $this->customer_db->db = $db_config;
- }
- $this->debug = new Debug();
- $this->debug->prefix = 'Mysql_Db::Mysql_CustomerAddress';
- $this->debug->On();
- $this->customer_db->debug->On();
- }
- Function InitDbConnection() {
- /*
- Make sure the database handle is available
- ( if not try to open it )
- */
- $returns = Array();
- if ( $this->customer_db->connection_init == false) {
- $returns = $this->customer_db->CreateConnection();
- }
- /* Oh no we failed to open the connection */
- if ( $this->customer_db->connection_init == false ) {
- return array( false, 'Database not connected', $returns );
- }
- return array( true );
- }
- Function Add( $address_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_address = $this->customer_db->PrepareSql(
- $sql_util->InsertStatement(
- 'address_table',
- Array(
- 'user_id' => $address_obj->user_id,
- 'address_name' => $address_obj->address_name,
- 'address' => $address_obj->address,
- 'city' => $address_obj->city,
- 'state' => $address_obj->state,
- 'zip' => $address_obj->zip,
- 'country' => $address_obj->country,
- 'mailing_address' => $address_obj->mailing_address,
- 'last_update_by' => $address_obj->last_update_by,
- 'last_update' => $address_obj->last_update
- )
- )
- );
- list( $ret_val, $reason ) = $insert_address->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Insert to table failed.' );
- } else {
- return Array( true );
- }
- } /* End add */
- Function ListAll( $user_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_addresses = $this->customer_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'address_table' ),
- Array(
- 'address_id',
- 'user_id', 'address_name',
- 'address', 'city',
- 'state', 'zip',
- 'country', 'mailing_address',
- 'last_update_by', 'last_update'
- ),
- 'user_id = ' . $user_id
- )
- );
- $t_array = Array();
- while( list(
- $address_id,
- $user_id, $address_name,
- $address, $city,
- $state, $zip,
- $country, $mailing_address,
- $last_update_by, $last_update
- ) = $get_addresses->FetchRow() ) {
- $t_obj = new CustomerAddress();
- $t_obj->address_id = $address_id;
- $t_obj->user_id = $user_id;
- $t_obj->address_name = $address_name;
- $t_obj->address = $address;
- $t_obj->city = $city;
- $t_obj->state = $state;
- $t_obj->zip = $zip;
- $t_obj->country = $country;
- $t_obj->mailing_address = $mailing_address;
- $t_obj->last_update_by = $last_update_by;
- $t_obj->last_update = $last_update;
- $t_array[] = $t_obj;
- }
- return $t_array;
- }
- Function Get( $address_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_addresses = $this->customer_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'address_table' ),
- Array(
- 'address_id',
- 'user_id', 'address_name',
- 'address', 'city',
- 'state', 'zip',
- 'country', 'mailing_address',
- 'last_update_by', 'last_update'
- ),
- 'address_id = ' . $address_id
- )
- );
- $t_array = Array();
- list( $address_id, $user_id, $address_name,
- $address, $city, $state,
- $zip, $country, $mailing_address,
- $last_update_by, $last_update
- ) = $get_addresses->FetchRow();
- $t_obj = new CustomerAddress();
- $t_obj->address_id = $address_id;
- $t_obj->user_id = $user_id;
- $t_obj->address_name = $address_name;
- $t_obj->address = $address;
- $t_obj->city = $city;
- $t_obj->state = $state;
- $t_obj->zip = $zip;
- $t_obj->country = $country;
- $t_obj->mailing_address = $mailing_address;
- $t_obj->last_update_by = $last_update_by;
- $t_obj->last_update = $last_update;
- return $t_obj;
- }
- Function Delete( $address_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->customer_db->PrepareSql(
- $sql_util->DeleteStatement(
- 'address_table',
- 'address_id = ' . $address_id
- )
- );
- list( $ret_val, $reason ) = $delete_domain->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Delete of address failed.' );
- } else {
- return Array( true );
- }
- }
- Function Modify( $address_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->customer_db->PrepareSql(
- $sql_util->UpdateStatement(
- 'address_table',
- Array(
- 'user_id' => $address_obj->user_id,
- 'address_name' => $address_obj->address_name,
- 'address' => $address_obj->address,
- 'city' => $address_obj->city,
- 'state' => $address_obj->state,
- 'zip' => $address_obj->zip,
- 'country' => $address_obj->country,
- 'mailing_address' => $address_obj->mailing_address,
- 'last_update_by' => $address_obj->last_update_by,
- 'last_update' => $address_obj->last_update
- ),
- 'address_id = ' . $address_obj->address_id
- )
- );
- list( $ret_val, $reason ) = $update_domain->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Update of domain failed.' );
- } else {
- return Array( true );
- }
- }
- }
- ?>