Mysql_User_Theme_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:5k
- <?php
- class Mysql_User_Theme_Db extends BaseObject {
- var $debug;
- var $user_db;
- Function Mysql_User_Theme_Db( $db_config = '' ) {
- $this->BaseObject( 'Mysql_User_Theme_Db' );
- $this->user_db = new Mysql_Db();
- if ( is_object( $db_config ) ) {
- $this->user_db->db = $db_config;
- }
- $this->debug = new Debug();
- $this->debug->prefix = 'Mysql_Db::Mysql_User_Theme';
- $this->debug->Off();
- $this->user_db->debug->Off();
- }
- Function InitDbConnection() {
- /*
- Make sure the database handle is available
- ( if not try to open it )
- */
- $returns = Array();
- if ( $this->user_db->connection_init == false) {
- $returns = $this->user_db->CreateConnection();
- }
- /* Oh no we failed to open the connection */
- if ( $this->user_db->connection_init == false ) {
- return array( false, 'Database not connected', $returns );
- }
- return array( true );
- }
- Function ListAll() { /* NA */ }
- Function Add( $theme_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_theme = $this->user_db->PrepareSql(
- $sql_util->InsertStatement(
- 'user_theme_table',
- Array(
- 'user_id' => $theme_obj->user_id,
- 'theme' => $theme_obj->theme_name
- )
- )
- );
- list( $ret_val, $reason ) = $insert_theme->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Insert to table failed.' );
- } else {
- return Array( true );
- }
- } /* End add */
- 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_theme = $this->user_db->PrepareSql(
- $sql_util->DeleteStatement(
- 'user_theme_table',
- 'user_id = ' . $user_id
- )
- );
- list( $ret_val, $reason ) = $delete_theme->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Delete of theme 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_theme = $this->user_db->PrepareSql(
- $sql_util->SelectStatement(
- Array( 'user_theme_table' ),
- Array( 'user_id', 'theme' ),
- 'user_id = ' . $user_id
- )
- );
- if ( ! (
- list( $user_id, $theme_name ) = $get_theme->FetchRow()
- ) ) {
- return Array( false, 'No match found.' );
- } else {
- $theme_obj = new User_Theme();
- $theme_obj->user_id = $user_id;
- $theme_obj->theme_name = $theme_name;
- return Array( true, $theme_obj );
- }
- }
- Function Modify( $theme_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_theme = $this->user_db->PrepareSql(
- $sql_util->UpdateStatement(
- 'user_theme_table',
- Array(
- 'theme' => $theme_obj->theme_name
- ),
- 'user_id = ' . $theme_obj->user_id
- )
- );
- list( $ret_val, $reason ) = $update_theme->Exec();
- if ( ! $ret_val ) {
- return Array( false, 'Update of theme failed.' );
- } else {
- return Array( true );
- }
- }
- }
- ?>