Mysql distributed native sub-table (revised) 03

Ideas:

1. Update the sub-table data after taking the modulus according to the id.
2. The two steps will update the total table sql should be inserted into the redis message queue, and update the total table data through asynchronous timing tasks

Implementation code

<?php
require './RunDbPdo.php';
$model = new RunDbPdo();
$model->configFile = './config/user.config.php';
if (isset($_GET) && !empty($_GET)) {
    
    
    extract($_GET);
    $user_id = isset($user_id) ? $user_id : '';
    $sql = "select * from mm_user where user_id='{
      
      $user_id}'";
    $data = $model->getRow($sql);
}

if (isset($_POST) && !empty($_POST)) {
    
    
    extract($_POST);
    $user_id = isset($user_id) ? $user_id : 0;
    $username = isset($username) ? $username : 0;
    $age = isset($age) ? $age : 0;
    //1、根据id取模后更新分表数据
    $d = $user_id % 2;
    $sql2 = "update mm_user{
      
      $d} set username='{
      
      $username}',age='{
      
      $age}' where user_id='{
      
      $user_id}'";
    $res2 = $model->query($sql2);
    //2、这二步将更新总表sql应该插入redis消息队列,通过异步定时任务更新总表数据
    if($res2) {
    
    
        $sql = "update mm_user set username='{
      
      $username}',age='{
      
      $age}' where user_id='{
      
      $user_id}'";
        $res = $model->query($sql);
    }
    if($res2){
    
    
        header('location:findAll.php');
    }
}

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户管理系统</title>
    <link href="./css/property-system.css" rel="stylesheet">
    <link href="./css/operate-system.css" rel="stylesheet">
</head>
<body>
<main>
    <section class="content">
        <fieldset class="form-list-32">
            <h3 class="operate-title-1"><i></i>编辑用户信息</h3>
            <form action="edit.php" id="editFormId" method="post" autocomplete="off">
                <ul>
                    <input type="hidden" name="user_id" value="<?= $data['user_id'] ?>">
                    <li><h6>用户名:</h6>
                        <aside><input type="text" name="username" value="<?= $data['username'] ?>"
                                      class="tbox30 tbox30-6"/></aside>
                    </li>
                    <li><h6>年龄:</h6>
                        <aside><input name="age" value="<?= $data['age'] ?>" maxlength="11" class="tbox30 tbox30-6"
                                      type="text"></aside>
                    </li>
                    <li class="agent-subbtn-wrap mt30px">
                        <h6>&nbsp;</h6>
                        <aside><input class="btn-2" type="submit" value="提交"></aside>
                    </li>
                </ul>

            </form>
        </fieldset>
    </section>
</main>
</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_39218464/article/details/114440453