删除一条数据时,删除其他表的关联数据-成都快上网建站

删除一条数据时,删除其他表的关联数据

$tableStr = $this->_getUserField();
$tableArr = explode('|', $tableStr);
$uidStr = implode(',', $uid_array);
$prefix = C('DB_PREFIX'); //表前缀
foreach ($tableArr as $table){
$vo = explode(':', $table);
$sql = 'DELETE FROM '.$prefix.$vo[0].' WHERE '.$vo[1].' IN ('.$uidStr.')';
$this->execute($sql);
}

成都创新互联专注于宕昌网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供宕昌营销型网站建设,宕昌网站制作、宕昌网页设计、宕昌网站官网定制、重庆小程序开发服务,打造宕昌网络公司原创品牌,更为您提供宕昌网站排名全网营销落地服务。

    private function _getUserField() {

    $dbName = C ( 'DB_NAME' );
    $sql = "SELECT TABLE_NAME,COLUMN_NAME FROM information_schema.`COLUMNS` WHERE TABLE_SCHEMA='$dbName' AND COLUMN_NAME LIKE '%uid%'";
    $list = M ()->query ( $sql );
    if (empty ( $list )) {
        $str .= '|atme:uid|attach:uid|blog:uid|blog_category:uid|channel:uid|channel_follow:uid|check_info:uid|collection:uid|comment:app_uid|comment:uid|comment:to_uid|credit_user:uid|denounce:uid|denounce:fuid|develop:uid|diy_page:uid|diy_widget:uid|event:uid|event_photo:uid|event_user:uid|feed:uid|feedback:uid|find_password:uid|invite_code:inviter_uid|invite_code:receiver_uid|login:uid|login:type_uid|login_logs:uid|login_record:uid|medal_user:uid|message_content:from_uid|message_list:from_uid|message_member:member_uid|notify_email:uid|notify_message:uid|online:uid|online_logs:uid|online_logs_bak:uid|poster:uid|sitelist_site:uid|survey_answer:uid|task_receive:uid|task_user:uid|template_record:uid|tipoff:uid|tipoff:bonus_uid|tipoff_log:uid|tips:uid|user:uid|user_app:uid|user_blacklist:uid|user_category_link:uid|user_change_style:uid|user_credit_history:uid|user_data:uid|user_department:uid|user_follow:uid|user_follow_group:uid|user_follow_group_link:uid|user_group_link:uid|user_official:uid|user_online:uid|user_privacy:uid|user_profile:uid|user_verified:uid|vote:uid|vote_user:uid|vtask:uid|vtask:bonus_uid|vtask_log:uid|weiba:uid|weiba:admin_uid|weiba_apply:follower_uid|weiba_apply:manager_uid|weiba_favorite:uid|weiba_favorite:post_uid|weiba_follow:follower_uid|weiba_log:uid|weiba_post:post_uid|weiba_post:last_reply_uid|weiba_reply:post_uid|weiba_reply:uid|weiba_reply:to_uid|x_article:uid|x_logs:uid';
    } else {
        $prefix = C('DB_PREFIX');
        foreach ( $list as $vo ) {
            $vo['TABLE_NAME'] = str_replace($prefix,'', $vo['TABLE_NAME']);
            $str .= '|' . $vo ['TABLE_NAME'] . ':' . $vo ['COLUMN_NAME'];
        }
    }

    return $str;
}

分享题目:删除一条数据时,删除其他表的关联数据
网站URL:http://kswjz.com/article/ijiehg.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流