Mysql_User_Signature_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:5k
源码类别:
WEB邮件程序
开发平台:
PHP
- <?php
- class Mysql_User_Signature_Db extends BaseObject {
- var $debug;
- var $signature_db;
- Function Mysql_User_Signature_Db( $db_config = '' ) {
- $this->BaseObject( 'Mysql_User_Signature_Db' );
- $this->signature_db = new Mysql_Db();
- if ( is_object( $db_config ) ) {
- $this->signature_db->db = $db_config;
- }
- $this->debug = new Debug();
- $this->debug->prefix = 'Mysql_Db::Mysql_User_Signature';
- }
- Function InitDbConnection() {
- /*
- Make sure the database handle is available
- ( if not try to open it )
- */
- $returns = Array();
- if ( $this->signature_db->connection_init == false) {
- $returns = $this->signature_db->CreateConnection();
- }
- /* Oh no we failed to open the connection */
- if ( $this->signature_db->connection_init == false ) {
- return array( false, 'Database not connected', $returns );
- }
- return array( true );
- }
- Function ListAll() {}
- Function Add( $signature_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_signature = $this->signature_db->PrepareSql(
- $sql_util->InsertStatement(
- 'user_signatures_table',
- Array(
- 'user_id' => $signature_obj->user_id,
- 'signature' => $signature_obj->signature
- )
- )
- );
- list( $ret_val, $reason ) = $insert_signature->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Insert to table failed.' );
- } else {
- return Array( true );
- }
- } /* End get */
- Function Delete( $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 */
- $delete_signature = $this->signature_db->PrepareSql(
- $sql_util->DeleteStatement(
- 'user_signatures_table',
- 'user_id = ' . $user_id
- )
- );
- list( $ret_val, $reason ) = $delete_signature->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Delete of signature failed.' );
- } else {
- return Array( true );
- }
- }
- Function Get( $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_signature = $this->signature_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'user_signatures_table' ),
- Array( 'user_id', 'signature' ),
- 'user_id = ' . $user_id
- )
- );
- if ( ! (
- list( $user_id, $signature ) = $get_signature->FetchRow()
- ) ) {
- return Array( false, 'No match found.' );
- } else {
- $signature_obj = new Pimp_Signature();
- $signature_obj->user_id = $user_id;
- $signature_obj->signature = $signature;
- return Array( true, $signature_obj );
- }
- }
- Function Modify( $signature_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_signature = $this->signature_db->PrepareSql(
- $sql_util->UpdateStatement(
- 'user_signatures_table',
- Array(
- 'signature' => $signature_obj->signature
- ),
- 'user_id = ' . $signature_obj->user_id
- )
- );
- list( $ret_val, $reason ) = $update_signature->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Update of signature failed.' );
- } else {
- return Array( true );
- }
- }
- }
- ?>