分庫分表插入資料

HelloWorld-Q發表於2020-12-09
<?php
$default = array(
    'unix_socket' => null,
  'host' => '192.168.8.112',
  'port' => '3306',
  'user' => 'slave',
  'password' => 'root',
);

//高可用的IP(keepalived)
//讀的也配置了,那是因為主可能掛掉
$db_133 = array(
   'unix_socket' => null,
  'host' => '192.168.8.101',
  'port' => '3306',
  'user' => 'slave',
  'password' => 'root',
);


// 唯一uid
function create_uuid($prefix = ""){    //可以指定字首
  $str = md5(uniqid(mt_rand(), true));
  $uuid = substr($str,0,8) . '-';
  $uuid .= substr($str,8,4) . '-';
  $uuid .= substr($str,12,4) . '-';
  $uuid .= substr($str,16,4) . '-';
  $uuid .= substr($str,20,12);
  return $prefix . $uuid;
}

# 準備的資料
$data=array(
  'id'=>$userId,
  'username'=>'喬飛飛',
  'password' =>'1074983188',
  'age'=>1,
  'sex' => 1,
  'status' => 1,
  'birthday' => date("Y-m-d h:i:s"),
  'create_at' => date("Y-m-d h:i:s"),
  'update_at' => date("Y-m-d h:i:s")
);

結果插入得到user_5庫user7表中
分庫分表插入資料

分庫分表插入資料

本作品採用《CC 協議》,轉載必須註明作者和本文連結
有夢想的人睡不著,沒有夢想的人睡不醒。

相關文章