Mysql_CustomerPhoneNumber_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:7k
源码类别:
WEB邮件程序
开发平台:
PHP
- <?php
- class Mysql_CustomerPhoneNumber_Db extends BaseObject {
- var $debug;
- var $customer_db;
- Function Mysql_CustomerPhoneNumber_Db( $db_config ) {
- $this->BaseObject( 'Mysql_CustomerPhoneNumber_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_CustomerPhoneNumber';
- $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( $phone_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_phone = $this->customer_db->PrepareSql(
- $sql_util->InsertStatement(
- 'phone_num_table',
- Array(
- 'user_id' => $phone_obj->user_id,
- 'phone_number_name' => $phone_obj->phone_number_name,
- 'phone_number' => $phone_obj->phone_number,
- 'phone_number_notes' => $phone_obj->phone_number_notes,
- 'contact_number' => $phone_obj->contact_number
- )
- )
- );
- list( $ret_val, $reason ) = $insert_phone->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_phones = $this->customer_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'phone_num_table' ),
- Array(
- 'phone_num_id', 'user_id',
- 'phone_number_name', 'phone_number',
- 'phone_number_notes', 'contact_number'
- ),
- 'user_id = ' . $user_id
- )
- );
- $t_array = Array();
- while( list(
- $phone_num_id, $user_id,
- $phone_number_name, $phone_number,
- $phone_number_notes, $contact_number
- ) = $get_phones->FetchRow() ) {
- $t_obj = new CustomerPhoneNumber();
- $t_obj->phone_num_id = $phone_num_id;
- $t_obj->user_id = $user_id;
- $t_obj->phone_number_name = $phone_number_name;
- $t_obj->phone_number = $phone_number;
- $t_obj->phone_number_notes = $phone_number_notes;
- $t_obj->contact_number = $contact_number;
- $t_array[] = $t_obj;
- }
- return $t_array;
- }
- Function Get( $phone_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_phones = $this->customer_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'phone_num_table' ),
- Array(
- 'phone_num_id', 'user_id',
- 'phone_number_name', 'phone_number',
- 'phone_number_notes', 'contact_number'
- ),
- 'phone_num_id = ' . $phone_id
- )
- );
- $t_array = Array();
- list( $phone_num_id, $user_id,
- $phone_number_name, $phone_number,
- $phone_number_notes, $contact_number
- ) = $get_phones->FetchRow();
- $t_obj = new CustomerPhoneNumber();
- $t_obj->phone_num_id = $phone_num_id;
- $t_obj->user_id = $user_id;
- $t_obj->phone_number_name = $phone_number_name;
- $t_obj->phone_number = $phone_number;
- $t_obj->phone_number_notes = $phone_number_notes;
- $t_obj->contact_number = $contact_number;
- return $t_obj;
- }
- Function Delete( $phone_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_phone = $this->customer_db->PrepareSql(
- $sql_util->DeleteStatement(
- 'phone_num_table',
- 'phone_num_id = ' . $phone_id
- )
- );
- list( $ret_val, $reason ) = $delete_phone->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Delete of phone failed.' );
- } else {
- return Array( true );
- }
- }
- Function Modify( $phone_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(
- 'phone_num_table',
- Array(
- 'user_id' => $phone_obj->user_id,
- 'phone_number_name' => $phone_obj->phone_number_name,
- 'phone_number' => $phone_obj->phone_number,
- 'phone_number_notes' => $phone_obj->phone_number_notes,
- 'contact_number' => $phone_obj->contact_number
- ),
- 'phone_num_id = ' . $phone_obj->phone_num_id
- )
- );
- list( $ret_val, $reason ) = $update_domain->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Update of phone failed.' );
- } else {
- return Array( true );
- }
- }
- }
- ?>